Answered step by step
Verified Expert Solution
Question
1 Approved Answer
module SS = Set.Make ( String ) module SMap = Map.Make ( String ) module IMap = Map.Make ( Int ) open Listopen Charopen Formatexception
module SS Set.MakeStringmodule SMap Map.MakeStringmodule IMap Map.MakeIntopen Listopen Charopen Formatexception Notimplementedexception Parseexnexception NotAbs of stringexception NotFound of stringexception DuplicateVar of string Data Definitions type label stringtype typ TUnit TBool TNat TFun of typ typ TRef of typ TVariant of label typ list TBottype term TmVar of string TmAbs of string typ term TmApp of term term TmUnit TmTrue TmFalse TmIf of term term term TmZero TmSucc of term TmPred of term TmIsZero of term TmVariant of label term typ eg red as red:Nat; blue:Nat TmCase of term label string term list eg case red of red x blue y TmRef of term TmLoc of int TmBang of term t TmAssn of term term TmRaise of term TmTry of term term TmNull TmIsNull of typ term Variants Implement an option type, some and none as variants let tpopt tp : typ : typ raise Notimplemented let tmsome t : termtp : typ : term raise Notimplementedlet tmnone tp : typ : term raise Notimplemented Implement an exception type as a variant. There are at least three possible exceptions that you should be able to handle. These should become clear as you progress through the homework, but feel free to start with some obvious candidates. No points will be deducted for having extra exceptions.let tpexn : typ raise Notimplemented Smallstep evaluation Implement the smallstep evaluation relations from class. Note the presence of a store and the possibility of encountering raise and null. type store term IMap.tlet rec cbv t : termmu : store : termstore option raise Notimplementedlet rec multistep t : termmu : store : termstore raise Notimplemented Typechecking utilities type ctx typ SMap.ttype typstore typ IMap.t let emptyctx : ctx SMap.emptylet emptystore : typstore IMap.empty look up a given variable's typ throw a NotFound exception if the variable is not found let lookup g : ctxx : string : typ match SMap.findopt x g with Some t t None raise NotFound x extend a context with a new variabletyp association let extend g : ctxx : stringt : typ: ctx if SMap.mem x g then raise DuplicateVar x else SMap.add x t g Typechecking check if a term has the given type. Takes in a context and a store, as well as a term t and type T Returns true iff gamma sigma t : T let typecheck g : ctxs : typstoret : termtp : typ raise Notimplemented This should infer the type of a term in the given context return None if the term is illtyped and typeinfer g : ctxs : typstoret : term : typ option raise Notimplemented Checks if the given store is well typed with respect to the given typestore and typing context. Returns true iff gamma sigma mu let storewelltyped g : ctxs : typstoremu : store raise Notimplemented
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started