Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Programming Language Expert

Submit this Haskell file with the questions completed.

**What you can use.** In this assignment, you can use anything from the lectures, the given Haskell file (including what's imported) and anything in the Prelude. Nothing more though. The first two import lines at the beginning of the file can be ignored. They're just for the parser. The next two are useful but you don't need to use them.

**Debugging.** You might find the debugger useful. It's imported above. It's quite easy to use the basic tracing facility. See the Haskell Hierarchical Libraries documentation for info on how to use it:

https://downloads.haskell.org/~ghc/latest/docs/html/libraries/

The assignment is to implement the evaluator for the language L discussed in class. You should review the notes from that class. There is also a complete description of the language in this file.

## Description of L

Expressions (abstract and concrete syntax):

%x.e -- lambda abstraction, like \x->e in Haskell
e e' -- application
x,y,z -- variables
succ, pred, ifzero, 0, 1, 2....

Values:

0, 1, 2, 3,...
%x.e
succ, pred, ifzero
ifzero e
ifzero e e

Evaluation: e ==> v means e evaluates to value v. The rules below specify how to evaluate.

For an algorithmic view, you can read the rules bottom-up. E.g. the second rule can be read as saying that to evaluate an application expression e e', first evaluate e, and if you get a value of the form %x.b, continue by evaluating b[e'/x], and if that results in a value v, return that as the result of evaluating e e'.

There's a more algorithmic presentation of evaluation in the lectures notes. There are a few small differences, so please use the definition below as the specification for your evaluator.

-- QUESTION 1:
--
-- subst x e e': substitute e for all "free" occurrences of (Var x) in
-- e'. "Free" means that the variable it is not declared by a
-- surrounding %. For example, in the expression
--
-- x (%x. x (%y.xz)) (%y.x)

-- there are 5 occurrences of x. The first is "free". The second is
-- the parameter for the % expression and is never substituted for.
-- The third and fourth occurrences refer to the parameter of the
-- enclosing % expression. The fifth is free. Therefore if we
-- substitute 0 for x we get 0 (%x. x (%y.xz)) (%y.0)
subst :: Id -> Exp -> Exp -> Exp
subst = stub "subst"

-- QUESTION 2:
--
-- isClosed e is true if and only if there are no free variables in e
-- (see the discussion in the comment for subst).
-- Examples: (%x. %y. x y) is closed; (%x. y %y. x y) is not since the
-- first occurrence of y is free.
isClosed :: Exp -> Bool
isClosed = stub "isClosed"

-- QUESTION 3:
--
-- eval e = v where e ==> v. If there is no v such that e==>v, the
-- result is undefined. Assume that e is closed.
eval :: Exp -> Exp

eval = stub "eval"

run :: Exp -> String
run e =
if isClosed e
then pp $ eval e
else error "run: expression must be closed"

stub :: String -> a
stub s = error ("Not implemented: " ++ s)


Attachment:- assignment.zip

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M91413412
  • Price:- $120

Guranteed 48 Hours Delivery, In Price:- $120

Have any Question?


Related Questions in Programming Language

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

Task silly name testeroverviewcontrol flow allows us to

Task: Silly Name Tester Overview Control flow allows us to alter the order in which our programs execute. Building on our knowledge of variables, we can now use control flow to create programs that perform more than just ...

Assignmentquestion onegiving the following code snippet

Assignment Question One Giving the following code snippet. What kind of errors you will get and how can you correct it. A. public class HelloJava { public static void main(String args[]) { int x=10; int y=2; System.out.p ...

Question - create a microsoft word macro using vba visual

Question - Create a Microsoft Word macro using VBA (Visual Basic for Applications). Name the macro "highlight." The macro should highlight every third line of text in a document. (Imagine creating highlighting that will ...

Assignment - proposal literature review research method1

Assignment - Proposal, Literature Review, Research Method 1. Abstract - Summary of the knowledge gap: problems of the existing research - Aim of the research, summary of what this project is to achieve - Summary of the a ...

Structs and enumsoverviewin this task you will create a

Structs and Enums Overview In this task you will create a knight database to help Camelot keep track of all of their knights. Instructions Lets get started. 1. What the topic 5 videos, these will guide you through buildi ...

Php amp session managment assignment -this assignment looks

PHP & SESSION MANAGMENT ASSIGNMENT - This assignment looks at using PHP for creating cookies and session management. Class Exercise - Web Project: Member Registration/Login This exercise will cover adding data connectivi ...

Background informationthis assignment tests your

Background Information This assignment tests your understanding of and ability to apply the programming concepts we have covered throughout the unit. The concepts covered in the second half of the unit build upon the fun ...

Overviewthis tasks provides you an opportunity to get

Overview This tasks provides you an opportunity to get feedback on your Learning Summary Report. The Learning Summary Report outlines how the work you have completed demonstrates that you have met all of the unit's learn ...

Assignment task -q1 a the fibonacci numbers are the numbers

Assignment Task - Q1. (a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and are characterised by the fact that every number after the first two is the sum of the ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As