- 作业标题:CSCI 3137 - Assignment 3: Case Distinctions and Some Haskell
- 课程名称:Dalhouse University CSCI 3137 Principles of Programming Languages
- 完成周期:1天
Question 1: Implementation of Switch Statements (8 marks)
We discussed in class that switch statements can be implemented in many different
ways by the compiler. Consider the following switch statements in C or Java. Decide for
each statement which implementation among the ones discussed in class would
produce the best balance between producing a fast and small program. Justify your
answer.
。。。
Question 2: Some Simple Haskell Functions (8 marks)
2.a. Function Composition
Remember the function doubleAndShow we implemented in class. A perfectly good
implementation was
。。。
2.b. Making Characters Uppercase, Take 1
The Data.Char module has a function toUpper to convert characters to uppercase:
。。。
2.c. Making Characters Uppercase, Take 2
Repeat Question 2.b but use pattern guards to implement the case distinction:
。。。
2.d. Making a String Uppercase
Use your myToUpper function from Question 2.b or 2.c as a building block for a function
。。。
Submission
Assignments are due by 11:59 PM on the due date. Assignments must be submitted electronically via Brightspace. Only a single PDF is accepted. You can do your work on paper and then scan it and submit the scanned. If at all possible, scan your assignment instead of taking a photo. The result will be more readable. If you do need to take a photo, ensure proper lighting and that the camera is properly focused. If the marker cannot read your work, you don’t earn any marks. Even if you take a photo or photos, it is your responsibility to convert the photos to a single PDF with the pages in the correct order.