Skip to content

Commit e69803b

Browse files
committed
lots of tweaking
1 parent 143a3cb commit e69803b

File tree

7 files changed

+96
-18
lines changed

7 files changed

+96
-18
lines changed

HLint.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import "hint" HLint.HLint
2+
3+
ignore "Reduce duplication"
4+
ignore "Redundant lambda"
5+
ignore "Use >=>"
6+
ignore "Use const"
7+
ignore "Avoid lambda"

hopper.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ library
5656
Language.Hopper.Internal.Core.ANF
5757
Language.Hopper.Internal.Core.Literal
5858
Language.Hopper.Internal.Core.Eval
59+
Language.Hopper.Internal.Core.CPS
5960
-- Modules included in this library but not exported.
6061
-- other-modules:
6162

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

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
{-# LANGUAGE FlexibleContexts #-}
33
{-# LANGUAGE FlexibleInstances #-}
44
{-# LANGUAGE DeriveFunctor, DeriveFoldable, DeriveTraversable,DeriveAnyClass #-}
5-
{-# LANGUAGE StandaloneDeriving #-}
5+
-- {-# LANGUAGE StandaloneDeriving #-}
66
{-# LANGUAGE DeriveDataTypeable #-}
7-
{-# LANGUAGE KindSignatures #-}
8-
{-# LANGUAGE DeriveGeneric #-}
7+
-- {-# LANGUAGE KindSignatures #-}
8+
-- {-# LANGUAGE DeriveGeneric #-}
99

1010
module Language.Hopper.Internal.Core.ANF where
1111

@@ -18,11 +18,13 @@ import Control.Monad
1818
import Prelude.Extras
1919
import Bound
2020

21-
data Atom ty a = AtomVar !a
21+
data Atom ty a =
22+
AtomVar !a
2223
| AtomicLit !Literal
2324
| AtomLam ![(Text,Type ty,RigModel)] -- do we want to allow arity == 0, or just >= 1?
2425
!(Scope Text (ANF ty) a)
2526
deriving(Eq,Ord,Functor,Foldable,Traversable,Data,Show,Read)
27+
2628
instance Eq ty => Eq1 (Atom ty)
2729
instance Show ty => Show1 (Atom ty)
2830
instance Ord ty => Ord1 (Atom ty)
@@ -33,14 +35,10 @@ instance Show2 Atom
3335
instance Ord2 Atom
3436
instance Read2 Atom
3537

36-
--instance Applicative (Atom ty) where
37-
-- pure = AtomVar
38-
-- (<*>)= ap
3938

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)
39+
--data AnfRHS ty a = PrimApp | FunApp |
40+
41+
data ArgANF ty a = ArgVar a | ArgLit !Literal
4442

4543
data ANF ty a
4644
= ReturnNF !(Atom ty a)
@@ -50,11 +48,7 @@ data ANF ty a
5048
| LetApp (Atom ty a) (Atom ty a) (Scope () (ANF ty) a)
5149

5250
-- |
53-
deriving (
54-
Ord,
55-
Functor,
56-
Foldable,
57-
Traversable,
51+
deriving ( Ord, Functor, Foldable, Traversable,
5852
Data,
5953
Eq,
6054
Read,
@@ -76,6 +70,9 @@ instance Applicative (ANF ty) where
7670

7771
instance Monad (ANF ty) where
7872
(ReturnNF (AtomVar a)) >>=f = f a
73+
(ReturnNF (AtomicLit l)) >>= _f = ReturnNF $ AtomicLit l
74+
(ReturnNF (AtomLam bs bod)) >>= f = ReturnNF $ AtomLam bs (bod >>>= f)
75+
--( ( ) :@@ )
7976

8077
-- return = V
8178
--V a >>= f = f a
@@ -85,4 +82,3 @@ instance Monad (ANF ty) where
8582
--(x :@ y) >>= f = (x >>= f) :@ (y >>= f)
8683
--Lam t e >>= f = Lam t (e >>>= f)
8784
--Let t bs b >>= f = Let t ( bs >>= f) (b >>>= f)
88-
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module Language.Hopper.Internal.Core.CPS where

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ import Data.Typeable
66
import Data.Data
77

88
data Literal = LInteger !Integer | LRational !Rational | LNatural !Natural
9+
10+
-- should we add primop namessss?
911
deriving(Eq,Ord,Show,Read,Data,Typeable)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import Control.Lens
3838
import qualified Control.Monad.Trans.State.Strict as State
3939

4040
import Control.Monad.Free
41-
41+
import
4242
-- import Data.Bifunctor
4343
-- import Data.Bitraversable
4444
-- import Data.Bifoldable
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,72 @@
1+
{-# LANGUAGE ScopedTypeVariables #-}
2+
{-# LANGUAGE FlexibleContexts #-}
3+
{-# LANGUAGE FlexibleInstances #-}
4+
{-# LANGUAGE DeriveFunctor, DeriveFoldable, DeriveTraversable,DeriveAnyClass #-}
5+
{-# LANGUAGE StandaloneDeriving #-}
6+
{-# LANGUAGE DeriveDataTypeable #-}
7+
{-# LANGUAGE KindSignatures #-}
8+
{-# LANGUAGE DeriveGeneric #-}
9+
110
module Language.Hopper.Internal.Core.Term where
11+
12+
import Language.Hopper.Internal.Core.Literal
13+
import Language.Hopper.Internal.Core.Type
14+
import Data.Text (Text)
15+
import Data.Data
16+
import Bound
17+
import Prelude.Extras
18+
import Control.Monad
19+
import GHC.Generics (Generic)
20+
import Data.Traversable (fmapDefault,foldMapDefault)
21+
22+
data Exp ty a
23+
= V a
24+
| ELit Literal
25+
-- PrimApp a [Atomic a]
26+
| Force (Exp ty a) --- Force is a Noop on evaluate values,
27+
--- otherwise reduces expression to applicable normal form
28+
-- should force be more like seq a b, cause pure
29+
30+
| Delay (Exp ty a) --- Delay is a Noop on Thunked values, otherwise creates a thunk
31+
--- note: may need to change their semantics later?!
32+
| Exp ty a :@ Exp ty a
33+
| Lam [(Text,Type ty,RigModel)] -- do we want to allow arity == 0, or just >= 1?
34+
(Scope Text (Exp ty) a)
35+
| Let (Text,Type ty,RigModel) (Exp ty a) (Scope Text (Exp ty) a) -- [Scope Int Exp a] (Scope Int Exp a)
36+
deriving (Typeable,Data,Generic)
37+
deriving instance (Read a, Read ty) => Read (Exp ty a)
38+
deriving instance (Read ty) => Read1 (Exp ty)
39+
deriving instance (Show a, Show ty) => Show (Exp ty a)
40+
deriving instance (Show ty) => Show1 (Exp ty)
41+
deriving instance (Ord ty) => Ord1 (Exp ty)
42+
deriving instance (Ord ty,Ord a) => Ord (Exp ty a)
43+
deriving instance (Eq ty) => Eq1 (Exp ty)
44+
deriving instance (Eq a,Eq ty) => Eq (Exp ty a)
45+
46+
instance Functor (Exp ty) where fmap = fmapDefault
47+
48+
instance Foldable (Exp ty) where foldMap = foldMapDefault
49+
50+
instance Applicative (Exp ty) where
51+
pure = V
52+
(<*>) = ap
53+
54+
instance Traversable (Exp ty) where
55+
traverse f (V a) = V <$> f a
56+
traverse _f (ELit e) = pure $ ELit e
57+
traverse f (Force e) = Force <$> traverse f e
58+
traverse f (Delay e) = Delay <$> traverse f e
59+
traverse f (x :@ y) = (:@) <$> traverse f x <*> traverse f y
60+
traverse f (Lam t e) = Lam t <$> traverse f e
61+
traverse f (Let t bs b) = Let t <$> (traverse f) bs <*> traverse f b
62+
63+
64+
instance Monad (Exp ty) where
65+
-- return = V
66+
V a >>= f = f a
67+
Delay e >>= f = Delay $ e >>= f
68+
Force e >>= f = Force $ e >>= f
69+
ELit e >>= _f = ELit e -- this could also safely be a coerce?
70+
(x :@ y) >>= f = (x >>= f) :@ (y >>= f)
71+
Lam t e >>= f = Lam t (e >>>= f)
72+
Let t bs b >>= f = Let t ( bs >>= f) (b >>>= f)

0 commit comments

Comments
 (0)