CSCI 3137 - Assignment 9- Types


  • 作业标题:CSCI 3137 - Assignment 9: Types
  • 课程名称:Dalhouse University CSCI 3137 Principles of Programming Languages
  • 完成周期:1天

We discussed generic functions in class. They are functions that can be applied to arguments of different types, possibly subject to some constraints. For example, we may want to implement a sorting function that can sort any collection of type T<A> (using Java notation here), where A is a type that supports comparison, and T is any collection type. In Haskell, such a function would have the type

。。。

Question 1: Monomorphization and Variable Models (4 points)

In this question, we look at two implementation strategies for polymorphic functions using a simple problem as an illustration: reversing a sequence (list or vector). We’ll look at how we would implement such a function in Haskell and C++.

Question 2: When can we Monomorphize a Function? (4 points)

Functions such as reverse in Question 1 are easy to implement, because they need to work with any possible argument type a. This means that they cannot really do anything interesting with the values of type a that they manipulate. They can move them around, make copies of them, but they cannot apply any operations such as addition or conversion to uppercase to them, because such operations are generally only supported for specific types, not for all types.

….

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.


文章作者: IT神助攻
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 IT神助攻 !
  目录