by flebron · 12y ago · 0 comments
let x = id id id id id id id id id id id id id id id id id id id id id id id id
See how long that takes (add ids if your machine can take it). To deduce a type for x, ghci will use 2^k type variables, if you have k ids. This is easily seen by induction:If k = 1, then the type of x is a -> a. This takes 2 = 2^1 = 2^k variables. If k > 1, it is of the form id f. Let t be the type of f. t has 2^{k - 1} variables, by induction. Thus the outermost id must take something of type t (this is 2^{k - 1} variables) and produce something of that same type t (this is another 2^{k - 1} variables), that is, it's of type t -> t. 2^{k - 1} + 2^{k - 1} = 2^k.
Note that this information is purely at compile time. Haskell isn't typed at runtime, this is all just to check types. At runtime, x is a no-op, as expected.
Interesting, got an example? Also, what version of Scala were you on?
Current Scala (2.11) has many issues to be ironed out, but I'd be surprised if the topic at hand here were one of them.
"I wonder how they're related?"
You could replace `id' with something that expands things, like \x -> (x,x): let f = \x -> (x,x) in (f.f.f.f.f.f) ()
Now it builds exponentially large tuple types. (?) And going back to the example in the blog: let f = \x -> (x,x) in (f.f.f.f.f.f) id
This is the same as the spacemanaki's example, without explicitly labeling the d1,d2,d3... intermediates.