Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
CSE4102-HW3/env.sml
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
17 lines (13 sloc)
672 Bytes
This file contains 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
(*Used when trying to look up a name that doesn't exist*) | |
exception NameNotBound; | |
(*Maps a name as a string to its value as a given type*) | |
type 'a Env = string -> 'a; | |
(*Creates an empty Env which raises NameNotBound if var name a does not exist in Env*) | |
fun env_new () : 'a Env = fn x => raise NameNotBound; | |
(*Looks up the value of a given name in the given Env | |
Raises NameNotBound exception if name not found in the given Env*) | |
fun env_lookup (e : 'a Env) (x : string) : 'a = e x; | |
(*Adds a new element with the given name and value to the given Env*) | |
fun env_bind (e : 'a Env) (a : string) (b : 'a) : 'a Env = | |
fn (x : string) => if (x = a) then b | |
else e x; |