Permalink
Browse files

fixes bug that didn't bind a variable in the environment in a case an…

…alysis
  • Loading branch information...
1 parent 90d5a9d commit fc29d3098499d137f86e72aaedd5e1f32acaa25d @kmels committed Jul 29, 2013
Showing with 7 additions and 8 deletions.
  1. +4 −4 examples/interpreter/Lists.hs
  2. +3 −4 src/Language/Core/Interpreter/Evaluable.hs
View
8 examples/interpreter/Lists.hs
@@ -35,15 +35,15 @@ thousand = listHead myList
twoThousand = listHead . listTail $ myList
-- does not work
-first15Fibs = fib 1
+first15Fibs = map fib [1..15]
where
fib :: Int -> Int
fib 0 = 0
fib 1 = 1
fib n = fib (n-2) + fib (n-1)
-first5nats = take 5 naturals
-first3nats = take 1 first5nats
+first5nats = take 5 [0..]
+first3nats = take 1 [1..]
first5nats_length = length first5nats
@@ -70,7 +70,7 @@ takeTest4 = take (5-5) [1,2,3]
takeTest5 = take 1 [1]
takeTest6 = take 2 [1,2,3]
-sumFirstFifty = sum [1..2]
+sumFirstFifty = sum [1..10]
false1 :: Bool
false1 = (takeTest2 :: [Int]) == (takeTest1 :: [Int])
View
7 src/Language/Core/Interpreter/Evaluable.hs
@@ -233,8 +233,7 @@ instance Evaluable Exp where
Pointer ptr -> evalExpI exp ((var_name,ptr_address ptr):env) "Evaluating Lambda body (exp)"
w@(Wrong _) -> return w
- -- lambda abstraction over variables
- -- ignores the type argument, evaluating the expression
+ -- lambda abstraction over a type variable
eval e@(Lam (Tb (var_name,_)) exp) env = do
whenFlag show_subexpressions $ indentExp e >>= \e -> debugM $ "Evaluating subexpression " ++ e
watchReductionM $ "Saving type " ++ var_name ++ " as a free type var"
@@ -246,7 +245,7 @@ instance Evaluable Exp where
maybePtr <- mkPointer (zDecodeQualified qvar) env
case maybePtr of
Just ptr -> eval ptr env
- Nothing -> return $ Wrong $ "Could not find var in env " ++ zDecodeQualified qvar
+ Nothing -> return $ Wrong $ "Could not find var in env " ++ zDecodeQualified qvar ++ ".."
eval (Dcon qcon) env = getPointer (zDecodeQualified qcon) env >>= flip eval env
@@ -267,7 +266,7 @@ instance Evaluable Exp where
-- bind those free variables contained in the matched alternative pattern
watchReductionM $ "Binding free variables contained in the matched pattern"
free_vars_env <- mkAltEnv exp_value matched_pattern
- eval (patternExpression matched_pattern) (free_vars_env ++ env)
+ eval (patternExpression matched_pattern) (exp_ref:(free_vars_env ++ env))
eval (Lit lit) _ = eval lit []

0 comments on commit fc29d30

Please sign in to comment.