1 {-# LANGUAGE ConstraintKinds #-}
2 {-# LANGUAGE QuantifiedConstraints #-}
3 {-# LANGUAGE RankNTypes #-}
4 {-# LANGUAGE UndecidableInstances #-}
6 module Symantic.Compiler.Term where
8 import Control.Applicative (Applicative (..))
9 import Control.Monad (Monad (..))
10 import Data.Functor (Functor (..))
11 import GHC.Types (Constraint, Type)
13 import Symantic.Typer.Type (Ty)
15 type Semantic = GHC.Types.Type -> GHC.Types.Type
16 type Syntax = Semantic -> GHC.Types.Constraint
18 data ForallSem (syn :: Syntax) (a :: GHC.Types.Type) = ForallSem {unForallSem :: forall sem. syn sem => sem a}
21 ( forall sem. syn sem => Functor sem
23 Functor (ForallSem syn)
25 fmap f (ForallSem sem) = ForallSem (fmap f sem)
26 a <$ (ForallSem sem) = ForallSem (a <$ sem)
28 ( forall sem. syn sem => Applicative sem
29 , Functor (ForallSem syn)
31 Applicative (ForallSem syn)
33 pure a = ForallSem (pure a)
34 liftA2 f (ForallSem a) (ForallSem b) = ForallSem (liftA2 f a b)
35 (<*>) (ForallSem f) (ForallSem a) = ForallSem ((<*>) f a)
36 (<*) (ForallSem f) (ForallSem a) = ForallSem ((<*) f a)
37 (*>) (ForallSem f) (ForallSem a) = ForallSem ((*>) f a)
39 ( forall sem. syn sem => Monad sem
40 , Applicative (ForallSem syn)
44 (>>=) (ForallSem sa) f = ForallSem (sa >>= \a -> case f a of ForallSem sb -> sb)
48 -- * Interpreter 'Parser'
49 data TermVT syn = forall vs a.
51 { typeTermVT :: Ty () vs a
52 , unTermVT :: ForallSem syn a