1 {-# LANGUAGE ConstraintKinds #-}
2 {-# LANGUAGE ExistentialQuantification #-}
3 {-# LANGUAGE KindSignatures #-}
4 {-# LANGUAGE MultiParamTypeClasses #-}
5 {-# LANGUAGE Rank2Types #-}
6 {-# LANGUAGE ScopedTypeVariables #-}
7 {-# LANGUAGE TypeFamilies #-}
8 module TFHOE.Expr.Common where
10 import Data.Proxy (Proxy(..))
11 import GHC.Prim (Constraint)
15 -- * Class 'Expr_from'
17 class Expr_from raw (ty:: {-h-}* -> *) (ty_end:: {-h-}* -> *) where
22 -> Context (Var ty_end) hs
24 -> (forall h. ty_end h -> Forall_Repr_with_Context ty_end hs h
25 -> Either Error_Type ret)
26 -> Either Error_Type ret
28 -- ** Type 'Expr_from_Type'
30 -- | A type family recursively accumulating the expressions
31 -- an interpreter will have to support.
32 type family Expr_from_Type (ty:: * -> *) (repr:: * -> *) :: Constraint
33 type instance Expr_from_Type Type_End repr = ()
35 -- ** Type 'Forall_Repr_with_Context'
37 -- | A data type embedding a universal quantification over @repr@
38 -- to construct an expression polymorphic enough to stay
39 -- interpretable by different interpreters;
40 -- moreover the expression is abstracted by a 'Context'
41 -- built at parsing time.
42 data Forall_Repr_with_Context ty hs h
43 = Forall_Repr_with_Context
44 ( forall repr. Expr_from_Type ty repr =>
45 Context repr hs -> repr h )
47 -- ** Type 'Forall_Repr'
51 { unForall_Repr :: forall repr
52 . Expr_from_Type ty repr