@@ -14,6 +14,7 @@ import Language.Hopper.Internal.Core.Literal
14
14
import Data.Text (Text )
15
15
import Data.Data
16
16
17
+ import Control.Monad
17
18
import Prelude.Extras
18
19
import Bound
19
20
@@ -27,12 +28,26 @@ instance Show ty => Show1 (Atom ty)
27
28
instance Ord ty => Ord1 (Atom ty )
28
29
instance Read ty => Read1 (Atom ty )
29
30
31
+ instance Eq2 Atom
32
+ instance Show2 Atom
33
+ instance Ord2 Atom
34
+ instance Read2 Atom
35
+
36
+ -- instance Applicative (Atom ty) where
37
+ -- pure = AtomVar
38
+ -- (<*>)= ap
39
+
40
+ -- instance Monad (Atom ty) where
41
+ -- (AtomVar a) >>= f = f a
42
+ -- (AtomicLit l) >>= _f =AtomicLit l
43
+ -- (AtomLam bs bod) >>= f = AtomLam bs (bod >>>= f)
44
+
30
45
data ANF ty a
31
46
= ReturnNF ! (Atom ty a )
32
- | ELitNF ! Literal
47
+ -- | ELitNF !Literal
33
48
| ForceNF ! a ! a
34
49
| !(Atom ty a ) :@@ ! (Atom ty a )
35
- | LetDerivedNF a a (Scope () (ANF ty ) a )
50
+ | LetApp ( Atom ty a ) ( Atom ty a ) (Scope () (ANF ty ) a )
36
51
37
52
-- |
38
53
deriving (
@@ -49,6 +64,25 @@ instance Show ty => Show1 (ANF ty)
49
64
instance Ord ty => Ord1 (ANF ty )
50
65
instance Read ty => Read1 (ANF ty )
51
66
52
- instance Monad (ANF ty )
67
+ instance Eq2 ANF
68
+ instance Show2 ANF
69
+ instance Ord2 ANF
70
+ instance Read2 ANF
71
+
72
+
73
+ instance Applicative (ANF ty ) where
74
+ pure = \ x -> ReturnNF (AtomVar x)
75
+ (<*>) = ap
76
+
77
+ instance Monad (ANF ty ) where
78
+ (ReturnNF (AtomVar a)) >>= f = f a
79
+
80
+ -- return = V
81
+ -- V a >>= f = f a
82
+ -- Delay e >>= f = Delay $ e >>= f
83
+ -- Force e >>= f = Force $ e >>= f
84
+ -- ELit e >>= _f = ELit e -- this could also safely be a coerce?
85
+ -- (x :@ y) >>= f = (x >>= f) :@ (y >>= f)
86
+ -- Lam t e >>= f = Lam t (e >>>= f)
87
+ -- Let t bs b >>= f = Let t ( bs >>= f) (b >>>= f)
53
88
54
- instance Applicative (ANF ty )
0 commit comments