forked from dbyrne/arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Types.hs
executable file
·43 lines (34 loc) · 1012 Bytes
/
Types.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module Types ( Expr (..)
, Env (..)
, Exception
, FuncSig
, IOResult
, Result
, ListResult
) where
import Data.Map (Map)
import qualified Data.Vector as V
import Control.Monad.State
import Control.Monad.Error
data Expr = Integer Integer
| Symbol String
| Fn Func FuncSig
| Special Func FuncSig
| List [Expr]
| QuotedList [Expr]
| Vector (V.Vector Expr)
type FuncSig = [String]
type Func = Result
type SymbolTable = Map String Expr
data Env = Env SymbolTable (Maybe Env)
type Exception = ErrorT String IO
type Res a = StateT Env Exception a
type Result = Res Expr
type IOResult = Res ()
type ListResult = Res [Expr]
instance Show Expr where
show (Integer x) = show x
show (Symbol x) = x
show (Fn _ _) = "<function>"
show (Special _ _) = "<special-form>"
show (List x) = "(" ++ unwords (map show x) ++ ")"