1 -- term algebras
    2 
    3 module TA
    4 
    5 ( TCon, TCons, tconname, tconarity
    6 , STerm -- todo: do we need (..) to export instances with hbc?
    7 , stcon, stargs, starity, mksterm
    8 
    9 , var2id, var2exp, sterm2exp
   10 )
   11 
   12 where
   13 
   14 
   15 import Set      -- syslib ghc
   16 
   17 import Ids
   18 import Syntax
   19 
   20 
   21 
   22 type TCon = Id
   23 
   24 tconname = idname
   25 tconarity = idarity
   26 
   27 type TCons = Set TCon
   28 
   29 
   30 data STerm a = STerm TCon [a]
   31         deriving (Eq, Ord, Show)
   32 
   33 -- hbc complains
   34 
   35 {- # SPECIALIZE instance Eq (STerm Int) #-}
   36 {- # SPECIALIZE instance Ord (STerm Int) #-}
   37 
   38 {- # SPECIALIZE instance Eq (STerm (Int, Int)) #-}
   39 {- # SPECIALIZE instance Ord (STerm (Int, Int)) #-}
   40 
   41 
   42 stcon (STerm tcon _) = tcon
   43 starity t = tconarity (stcon t)
   44 stargs (STerm _ args) = args
   45 mksterm tcon args = STerm tcon args
   46 
   47 -------------------------------------------------------------------
   48 
   49 var2id n = uservar ("x" ++ show n)
   50 var2exp n = App (var2id n) []
   51 
   52 sterm2exp t =
   53 
   54     let tc = stcon t
   55         vs = map var2exp (stargs t)
   56     in
   57         -- looks like a function
   58         App tc vs
   59 
   60 
   61 
   62 --------------------------------------------------------------------
   63