Skip to content

Commit 143a3cb

Browse files
committed
progress towards nice things
1 parent 4a57840 commit 143a3cb

File tree

1 file changed

+38
-4
lines changed
  • src/Language/Hopper/Internal/Core

1 file changed

+38
-4
lines changed

src/Language/Hopper/Internal/Core/ANF.hs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Language.Hopper.Internal.Core.Literal
1414
import Data.Text (Text)
1515
import Data.Data
1616

17+
import Control.Monad
1718
import Prelude.Extras
1819
import Bound
1920

@@ -27,12 +28,26 @@ instance Show ty => Show1 (Atom ty)
2728
instance Ord ty => Ord1 (Atom ty)
2829
instance Read ty => Read1 (Atom ty)
2930

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+
3045
data ANF ty a
3146
= ReturnNF !(Atom ty a)
32-
| ELitNF !Literal
47+
-- | ELitNF !Literal
3348
| ForceNF !a !a
3449
| !(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)
3651

3752
-- |
3853
deriving (
@@ -49,6 +64,25 @@ instance Show ty => Show1 (ANF ty)
4964
instance Ord ty => Ord1 (ANF ty)
5065
instance Read ty => Read1 (ANF ty)
5166

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)
5388

54-
instance Applicative (ANF ty)

0 commit comments

Comments
 (0)