Created
May 8, 2017 14:37
-
-
Save dcguim/7df4e17723746d31a7a04112868ffe69 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
----------------------------- -- 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