
On Mon, 26 May 2008, Andrew Coppin wrote:
Thomas Davie wrote:
This is perhaps best explained with an example of something that can be typed with rank-2 types, but can't be typed otherwise:
main = f id 4
f g n = (g g) n
We note that the same instance of id must be made to have both the type (Int -> Int) and ((Int -> Int) -> (Int -> Int)) at the same time. Rank 2 types allows us to do this.
What a perplexing example! :-}
Well anyway, I was under the impression that id :: x -> x, so I'm not really sure why this wouldn't work without Rank-2 types...
Because f's type can't be written as a rank-1 type - its parameter g must be polymorphic (forall x. x->x). With rank-1 types, all the instantiation is done by the caller - the function can't require that it receive polymorphic parameters. -- flippa@flippac.org Sometimes you gotta fight fire with fire. Most of the time you just get burnt worse though.