Answered step by step
Verified Expert Solution
Link Copied!

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.Make(String)module SMap = Map.Make(String)module IMap = Map.Make(Int)open Listopen Charopen Formatexception Not_implementedexception Parse_exnexception 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 =6 as [red:Nat; blue:Nat]*)| TmCase of term *(label * string * term) list (* eg. case red 2 of [red x =>5| blue y =>9]*)| 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 tp_opt (tp : typ) : typ = raise Not_implemented let tm_some (t : term)(tp : typ) : term = raise Not_implementedlet tm_none (tp : typ) : term = raise Not_implemented(* 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 tp_exn : typ = raise Not_implemented(* Small-step evaluation *)(* Implement the small-step 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 : term)(mu : store) : (term*store) option = raise Not_implementedlet rec multistep (t : term)(mu : store) : term*store = raise Not_implemented(* Typechecking utilities *)type ctx = typ SMap.ttype typ_store = typ IMap.t let empty_ctx : ctx = SMap.emptylet empty_store : typ_store = IMap.empty(* look up a given variable's typ, throw a NotFound exception if the variable is not found *)let lookup (g : ctx)(x : string) : typ = match SMap.find_opt x g with| Some t -> t| None -> raise (NotFound x)(* extend a context with a new variable-typ association *)let extend (g : ctx)(x : string)(t : 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 type_check (g : ctx)(s : typ_store)(t : term)(tp : typ)= raise Not_implemented(* This should infer the type of a term in the given context *)(* return None if the term is ill-typed *)and type_infer (g : ctx)(s : typ_store)(t : term) : typ option = raise Not_implemented(* Checks if the given store is well typed with respect to the given type_store and typing context. *)(* Returns true iff gamma | sigma |- mu *)let store_well_typed (g : ctx)(s : typ_store)(mu : store)= raise Not_implemented

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Semantics In Databases Second International Workshop Dagstuhl Castle Germany January 2001 Revised Papers Lncs 2582

Authors: Leopoldo Bertossi ,Gyula O.H. Katona ,Klaus-Dieter Schewe ,Bernhard Thalheim

2003rd Edition

3540009574, 978-3540009573

More Books

Students also viewed these Databases questions

Question

1. Which position would you take?

Answered: 1 week ago