Question: In this homework assignment, you will be representing System E in Haskell and writing functions to do type - checking, substitution / shifting , the
In this homework assignment, you will be representing System E in Haskell and writing functions to do typechecking, substitutionshifting the Progress theorem, and evaluation to a value.
First, download the file hwhs Download hwhs Working within this file, provide definitions for all functions currently returning undefined and test all your functions, creating several test expressions in your file and putting the test results in comments.
Turn in your edited and commented hwhs file here.
System
import Data.Char toupper
Abstract Syntax, using de Bruijn indices
Types
data Typ NumT StrT
Expressions
data Exp Var Int Num Int Str String
Plus Exp Exp Times Exp Exp Cat Exp Exp Len Exp
Let ExpExp
Contexts first element of list last element of ctx For example,
the context x:num, y:str z:str is represented as StrT StrT NumT
type Ctx Typ
An example expression with free variable z
Concrete syntax:
let
len
in
Abstract syntax:
let;;;;plus;
myexp : : Exp
myexp Let Str "abc"
Let Len Var
Times Len Cat Var Var
lus Create several more for your own testing
output format for abstract syntax, using variable names
Variable names to use for printing terms, chosen in the given order;
free variables are printed as uppercase
vars :: string
vars "xyuvwabcdefghijklmnopqrst"
instance Show Typ where
show NumT "num"
show StrT str
instance Show Exp where
show e showvars e where
showvars Var i toupper $vars!!
otherwise
showvars Num "num show
showvars Str sstr s
showvars Plus e e i
"plus showvars e i ; showvars e i
showvars Times e e
"times showvars e i ; showvars e i
showvars Cat e e i"cat showvars e i ; showvars e i
showvars Len e i
"len showvars e i
showvars Let e e
"let showvars e i ; vars i :
showvars ei
Maybevalued index lookup
look : : a Int Maybe a
look Nothing
look Nothing
look : Just
look : look
Closed terms
closed : : Exp Bool
closed undefined
Type checking Nothing not welltyped, Just has type
typof : : Ctx Exp Maybe Typ
typof e undefined
shift e add to all free variables in
shift :: Exp Int Exp
shift e undefined
subst substitute for in
subst : : Exp Int Exp Exp
subst e i e undefined Eager progress
data ProgressR Value Step Exp deriving Show
Assumes input is a welltyped expression you don't need to check this
Note: input might have free variables which are taken to be values
so be careful with the associated de Bruin indices!
prog : : Exp ProgressR
prog e undefined
Step a welltyped expression using prog
step :: Exp Exp
step case prog e of
Value e
Step e
Step a welltyped expression to a value using prog
steps :: Exp Exp
steps case prog e of
Value e
Step e steps e
Bigstep evaluation of welltyped terms
eval :: Exp Exp
eval e undefined
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
