Skip to content
Browse files

Improved plus pimitive to work with strings.

  • Loading branch information...
1 parent b8603f1 commit b3e5ae5ebfa0719dcc66c693bae02d51af6be85a Andy Kitchen committed Sep 16, 2011
Showing with 4 additions and 1 deletion.
  1. +4 −1 Primitives.hs
View
5 Primitives.hs
@@ -8,7 +8,7 @@ import Evaluate
defaultBindings :: IO Bindings
defaultBindings = sequence
[fromList hashString
- [("+", arithLift (+)),
+ [("+", PrimFun plusPrim),
("-", arithLift (-)),
("*", arithLift (*)),
("/", arithLift (/)),
@@ -37,6 +37,9 @@ arithLift :: (Number -> Number -> Number) -> Value
arithLift f =
PrimFun (\[(NumVal x),(NumVal y)] -> (return . NumVal) (f x y))
+plusPrim [(NumVal x),(NumVal y)] = (return . NumVal) (x + y)
+plusPrim [(StrVal x),(StrVal y)] = (return . StrVal) (x ++ y)
+
compLift :: (Value -> Value -> Bool) -> Value
compLift comp =
PrimFun (\[a, b] -> (return . BoolVal) (a `comp` b))

0 comments on commit b3e5ae5

Please sign in to comment.
Something went wrong with that request. Please try again.