module Tip.Haskell.Repr where
import Data.Foldable (Foldable)
import Data.Traversable (Traversable)
data Decls a = Decls [Decl a]
deriving (Eq,Ord,Show,Functor,Traversable,Foldable)
data Decl a
= TySig a
[Type a]
(Type a)
| FunDecl a [([Pat a],Expr a)]
| DataDecl a
[a]
[(a,[Type a])]
[a]
| InstDecl [Type a]
(Type a)
[Decl a]
| ClassDecl [Type a]
(Type a)
[Decl a]
| TypeDef (Type a) (Type a)
| Decl a `Where` [Decl a]
| TH (Expr a)
| Module String
| LANGUAGE String
| QualImport String (Maybe String)
deriving (Eq,Ord,Show,Functor,Traversable,Foldable)
funDecl :: a -> [a] -> Expr a -> Decl a
funDecl f xs b = FunDecl f [(map VarPat xs,b)]
data Type a
= TyCon a [Type a]
| TyVar a
| TyTup [Type a]
| TyArr (Type a) (Type a)
| TyForall [a] (Type a)
| TyCtx [Type a] (Type a)
| TyImp a (Type a)
deriving (Eq,Ord,Show,Functor,Traversable,Foldable)
modTyCon :: (a -> a) -> Type a -> Type a
modTyCon f t0 =
case t0 of
TyCon t ts -> TyCon (f t) (map (modTyCon f) ts)
TyVar x -> TyVar x
TyTup ts -> TyTup (map (modTyCon f) ts)
TyArr t1 t2 -> TyArr (modTyCon f t1) (modTyCon f t2)
data Expr a
= Apply a [Expr a]
| ImpVar a
| Do [Stmt a] (Expr a)
| Lam [Pat a] (Expr a)
| Let a (Expr a) (Expr a)
| ImpLet a (Expr a) (Expr a)
| List [Expr a]
| Tup [Expr a]
| String a
| Noop
| Case (Expr a) [(Pat a,Expr a)]
| Int Integer
| QuoteTyCon a
| QuoteName a
| THSplice (Expr a)
| Record (Expr a) [(a,Expr a)]
| Expr a ::: Type a
deriving (Eq,Ord,Show,Functor,Traversable,Foldable)
nestedTyTup :: [Type a] -> Type a
nestedTyTup [] = TyTup []
nestedTyTup (t:ts) = TyTup [t,nestedTyTup ts]
nestedTup :: [Expr a] -> Expr a
nestedTup [] = Tup []
nestedTup (d:ds) = Tup [d,nestedTup ds]
nestedTupPat :: [Pat a] -> Pat a
nestedTupPat [] = TupPat []
nestedTupPat (d:ds) = TupPat [d,nestedTupPat ds]
mkDo [] x = x
mkDo ss1 (Do ss2 e) = mkDo (ss1 ++ ss2) e
mkDo ss Noop = case (init ss,last ss) of
(i,Stmt e) -> mkDo i e
(i,Bind x e) -> mkDo i e
mkDo ss e = Do ss e
var :: a -> Expr a
var x = Apply x []
data Pat a = VarPat a | ConPat a [Pat a] | TupPat [Pat a] | WildPat | IntPat Integer
deriving (Eq,Ord,Show,Functor,Traversable,Foldable)
data Stmt a = Bind a (Expr a) | BindTyped a (Type a) (Expr a) | Stmt (Expr a)
deriving (Eq,Ord,Show,Functor,Traversable,Foldable)