aboutsummaryrefslogtreecommitdiff
path: root/haskell/Types.hs
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-12-23 20:35:48 -0700
committerJoel Martin <github@martintribe.org>2015-01-09 16:16:52 -0600
commitb76aa73bc76a28d7c6bb3c5a43acc9afd9ec42c8 (patch)
tree4b57f91dcf1df0e079a4251a1cab78fe0188dfb4 /haskell/Types.hs
parenta816262a057ecc4bd1fd07750d21cab81490f336 (diff)
downloadmal-b76aa73bc76a28d7c6bb3c5a43acc9afd9ec42c8.tar.gz
mal-b76aa73bc76a28d7c6bb3c5a43acc9afd9ec42c8.zip
Haskell: steps 0-3
Diffstat (limited to 'haskell/Types.hs')
-rw-r--r--haskell/Types.hs49
1 files changed, 49 insertions, 0 deletions
diff --git a/haskell/Types.hs b/haskell/Types.hs
new file mode 100644
index 0000000..bec26be
--- /dev/null
+++ b/haskell/Types.hs
@@ -0,0 +1,49 @@
+module Types
+--( MalVal (Nil,MalFalse,MalTrue,MalNumber,MalString,MalSymbol,MalKeyword,MalList,MalVector,MalFunc), _obj_type )
+(MalVal (..), FuncT (..), _malfunc, catchAny)
+where
+
+import qualified Data.Map as Map
+import Control.Exception (SomeException, catch)
+
+-- Based Mal types --
+newtype FuncT = FuncT (MalVal -> MalVal)
+data MalVal = Nil
+ | MalFalse
+ | MalTrue
+ | MalNumber Int
+ | MalString String
+ | MalSymbol String
+ | MalKeyword String
+ | MalList [MalVal]
+ | MalVector [MalVal]
+ | MalHashMap (Map.Map String MalVal)
+ | MalFunc FuncT
+ deriving (Eq)
+
+instance Eq FuncT where
+ x == y = False
+
+_malfunc f = MalFunc $ FuncT f
+
+
+-- Error definitions --
+catchAny :: IO a -> (SomeException -> IO a) -> IO a
+catchAny = catch
+
+
+----------------------------------------------------------
+
+-- General type functions --
+
+_obj_type :: MalVal -> String
+_obj_type (Nil) = "nil"
+_obj_type (MalFalse) = "false"
+_obj_type (MalTrue) = "true"
+_obj_type (MalNumber _) = "number"
+_obj_type (MalString _) = "string"
+_obj_type (MalSymbol _) = "symbol"
+_obj_type (MalList _) = "list"
+_obj_type (MalVector _) = "vector"
+_obj_type (MalHashMap _) = "hashmap"
+_obj_type (MalFunc _) = "malfunc"