haskell - Evaluating lambda expressions on the form lambda x E -
haskell - Evaluating lambda expressions on the form lambda x E -
i got problem trying evaluate lambda expressions on form lambda x e. after hours of thinking came nil yet, there here point me abit in right direction?
this should returning function argument x, can used on body e. function can thought of anonymous function on form \x -> e. variables can used in e, exist when function made(lexical scope).
i should back upwards evaluation of function calls on form f a. evaluating list ( f ... ) when f not special atom, successful when either f evaluates function, or list has 2 elements ( f ) , evaluating of function f argument succeeds , gives legitimate value, mean number of function.
the code i've got far handle cases leading following:
type context = [( string, int )] type memory = [( int, ast )] eval::ast -> context -> memory -> ( ast, context, memory ) eval (number x) con mem = ( number x, con, mem ) eval ( llist[number x] ) con mem = ( number x, con, mem ) eval ( llist[ atom "+", number x, number y]) con mem = ( number ( x + y ), con, mem ) eval ( llist[ atom "-", number x, number y]) con mem = ( number ( x - y ), con, mem ) eval ( llist[llist xs] ) con mem = eval (fstrip( eval( llist xs) con mem )) con mem eval ( llist[atom "-", number x, llist ys ]) con mem = eval(llist[ atom "-", number x, fstrip(eval (llist ys) con mem)]) con mem eval ( llist[atom "-", llist xs, number y ]) con mem = eval(llist[ atom "-", fstrip(eval (llist xs) con mem), number y ] ) con mem eval ( llist[atom "-", llist xs, llist ys ]) con mem = eval(llist[ atom "-", fstrip(eval( llist xs ) con mem), fstrip(eval ( llist ys ) con mem)]) con mem eval ( llist[atom "+", number x, llist ys ]) con mem = eval(llist[ atom "+", number x, fstrip(eval (llist ys) con mem)]) con mem eval ( llist[atom "+", llist xs, number y ]) con mem = eval(llist[ atom "+", fstrip(eval (llist xs) con mem), number y]) con mem eval ( llist[atom "+", llist xs, llist ys ]) con mem = eval(llist[ atom "+", fstrip( eval (llist xs) con mem), fstrip(eval( llist ys ) con mem ) ]) con mem eval ( llist[atom "if", x, y, z] ) con mem = if fstrip( eval x con mem ) == number 0 (eval y con mem) else (eval z con mem) fstrip (x, y, z) = x run::string -> ast run xs = fstrip( eval (parse xs) [] [] )
the type context , memory in no utilize yet, thought used during evaluation of lambda expressions.
edit: i'm sorry giving insufficient information. info ast looks this:
data ast = atom string | number int | function string ast context | llist [ast] deriving ( eq,show,ord )
a lambda expression( define ) on form: (lambda ), , function phone call given on form ( )
eval( llist( atom "lambda" : xs ) ) con mem
will way lhs of eval function @ least, when defining lambda expression. , come understanding @ to the lowest degree help function help evaluate functions, i'm still abit lost in dark on how proceed.
haskell lambda evaluation
Comments
Post a Comment