X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=exercises%2Fassignment5_hint4.mdwn;h=d718c9a7c01c5af843c731b43ff08616bc1c6cc2;hp=15f2d2a4d1e928093a6fe3b2ccb27b92058e5478;hb=a7f15a6a8100c10bde1cf7b97a02660a3d00b9d9;hpb=56341740e1fdfbee34cc0d1bf0dc893e18f447fa diff --git a/exercises/assignment5_hint4.mdwn b/exercises/assignment5_hint4.mdwn index 15f2d2a4..d718c9a7 100644 --- a/exercises/assignment5_hint4.mdwn +++ b/exercises/assignment5_hint4.mdwn @@ -261,12 +261,14 @@ And you won't have any of the kinds of difficulties we're discussing here with t By the way, this issue about not-enough-polymorphism doesn't arise in Haskell. Here are the Church numerals: - > data Church a = Church ((a->a)->a->a) - > let { zero::Church a; zero = Church (\s z -> z); one::Church a; one = Church (\s z -> s z); succ n = case n of { Church n -> Church (\s z-> s (n s z)) } } + > type Church a = (a -> a) -> a -> a + > let { zero :: Church a; zero = \s z -> z; one :: Church a; one = \s z -> s z; succ n = \s z-> s (n s z) } > let two = succ one - > case two of { Church n -> n ('S':) "0" } + > two ('S':) "0" "SS0" > :t two - two :: Church a + two :: (a -> a) -> a -> a + > two (1+) 0 + 2 The reason that OCaml has trouble here where Haskell doesn't has to do with some fundamental differences between their type systems, that we haven't yet explored. (Specifically, it has to do with the fact that OCaml has *mutable reference cells* in its type system, and this obliges it to place limits on where it generalizes type variables, else its type system becomes inconsistent.)