Skip to content

Instantly share code, notes, and snippets.

@dcguim
Created May 8, 2017 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcguim/7df4e17723746d31a7a04112868ffe69 to your computer and use it in GitHub Desktop.
Save dcguim/7df4e17723746d31a7a04112868ffe69 to your computer and use it in GitHub Desktop.
----------------------------- -- 001
-- Simple Functional Language -- 002
----------------------------- -- 003
-- variables are just names -- 006
type Var = String -- 007
-- 008
-- values are integers and functions -- 009
data Value = ValInt Integer -- 010
| ValFunc (Value -> Value) -- 011
| ValError String -- 012
-- 013
-- 014
-- an Environment maps variables to Values -- 015
type Env = Var -> Value
-- An empty Environment
emptyEnv :: Env
emptyEnv v = ValError ("undefined variable " ++ v)
-- bind a new value in an environment -- 029
bind :: Var -> Value -> Env -> Env -- 030
bind var val env = \v -> if var == v then val else env v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment