cs252r : Advanced Functional Programming - Fall 2006
These pages are a record of the in-class discussions for the graduate class "Advanced Functional Programming" given at Harvard University in the Fall of 2006.October 30, 2006
- A system of constructor classes: overloading and implicit higher-order polymorphism. Mark P. Jones.
- QuickCheck: a lightweight tool for random testing of Haskell programs. Koen Claessen and John Hughes.
Warm-up questions: Constructor Classes
What does Mark Jones mean by "higher-order polymorphism"?
In this setting, higher-order polymorphism means the ability to have type variables of higher kind.
remark: In this work, Jones means the ability to abstract over type variables of arbitrary kind. It does not mean that a variable can range over different kinds (kind polymorphism) -- each variable has a specific kind, and must be instantiated with a type constructor of that kind.
Jones's system cannot support a function that requires an argument to be overloaded or polymorphic. How is this restriction enforced by the type rules?
For example, here is a function that requires a polymorphic function argument:
high :: (forall a. a -> Int) -> (Int,Int) high f -> (f 1, f True)
When a function argument is put into the type environment, it is required to have a (non-polymorphic) tau-type. It is only in the let rule that (polymorphic) sigma-types are introduced into the type environment.
Do you have any questions about the unification algorithm?
Add a third data constructor to the Fork type such that the type parameter a is forced to have kind *->*
data Fork a = Prong
| Split (Fork a) (Fork a)
| Item (a Int)
QuickCheck
QuickCheck expresses universal algebraic properties such as:
forall x y z. (x+y) + z == x + (y+z)
Why didn't the designers of QuickCheck need to extend Haskell with an explicit forall construct?
no answers.
remark: We have lambda, so we can do all of our abstraction at the term level.
Under what circumstances is it acceptable to base a testing tool on code defined purely in within the implementation language, with no program analysis, transformation, instrumentation, or compiler support?
When you are not looking for a guarantee (proof) of correctness.
Is QuickCheck useful for testing interpreters?
Identify a property of your interpreter that is easy to test, and explain how you would go about it.
If you could generate random ASTs, then you could try:
parse (print x) == x
If you want to test your entire interpreter, what parts do you expect to be most difficult?
remark: It is very difficult to use QuickCheck to test that your interpreter rejects bad input.
BibTeX
@InProceedings{Mark-P.-Jones1993
, isbn = "0-89791-595-X"
, author = "Mark P. Jones"
, year = 1993
, publisher = "ACM Press"
, title = "A system of constructor classes: overloading and implicit higher-order polymorphism"
, address = "New York, NY, USA"
, location = "Copenhagen, Denmark"
, url = "http://doi.acm.org/10.1145/165180.165190"
, pages = "52--61"
, booktitle = "FPCA '93: Proceedings of the conference on Functional programming languages and computer architecture"
}
@InProceedings{Koen-Claessen-and-John-Hughes2000
, isbn = "1-58113-202-6"
, author = "Koen Claessen and John Hughes"
, publisher = "ACM Press"
, title = "QuickCheck: a lightweight tool for random testing of Haskell programs"
, address = "New York, NY, USA"
, year = 2000
, url = "http://doi.acm.org/10.1145/351240.351266"
, pages = "268--279"
, booktitle = "ICFP '00: Proceedings of the fifth ACM SIGPLAN international conference on Functional programming"
}