Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Factored interp into its own data type so we can try different interps.

  • Loading branch information...
commit 932a71616fad0c0db9cc85b58570c0fc08781c38 1 parent a930ddc
@luqui authored
View
22 experiments/lazy-hnf/LazyHNF/LazyNF.hs
@@ -1,5 +1,5 @@
module LazyHNF.LazyNF
- ( Val, Value(..), eval, getVal )
+ ( lazyNFInterp )
where
import LazyHNF.Exp
@@ -11,9 +11,6 @@ data Val a
| VPrim a
deriving (Show)
-class Value v where
- applyValue :: v -> v -> v
-
quote :: Int -> Val a -> Val a
quote by = go 0
where
@@ -42,13 +39,14 @@ VPrim p %% VLam body = error "Cannot apply a primitive to a lambda"
VPrim p %% t = VApp (VPrim p) t
exp %% arg = VApp exp arg
-getVal :: Val a -> Maybe a
-getVal (VPrim a) = Just a
-getVal _ = Nothing
+lazyNFInterp = Interp {
+ eval = getValNF . evalNF
+}
+getValNF (VPrim a) = Just a
+getValNF _ = Nothing
-eval :: (Value a) => Exp a -> Val a
-eval (a :% b) = eval a %% eval b
-eval (Lam body) = VLam (eval body)
-eval (Var z) = VVar z
-eval (Lit p) = VPrim p
+evalNF (a :% b) = evalNF a %% evalNF b
+evalNF (Lam body) = VLam (evalNF body)
+evalNF (Var z) = VVar z
+evalNF (Lit p) = VPrim p
View
2  experiments/lazy-hnf/interpreter.hs
@@ -86,7 +86,7 @@ layer :: Exp a -> Exp a
layer x = buildExp (eInterp_ % nil_) :% quote x
run :: Exp IVal -> Maybe IVal
-run exp = getVal (eval exp)
+run = eval lazyNFInterp
iter n = foldr (.) id . replicate n
Please sign in to comment.
Something went wrong with that request. Please try again.