
On Thu, Apr 03, 2014 at 04:21:38PM +0000, Simon Peyton Jones wrote:
Dominick's program is very delicate:
fibonacci :: (Integral a) => [a] fibonacci = 0 : 1 : zipWith (+) fibonacci (tail fibonacci)
Remember, the "(Integral a) =>" thing is very like "Integral a ->"; it's an extra value argument. Would you expect this program to be fast?
foo :: Int -> [Int] foo n = 0 : 1 : zipWith (+) (foo n) (tail (foo n))
Indeed. The curious may be interested to know you can fix this by hand by sharing a monomorphic bind fibonacci = let f = fibonacci in 0 : 1 : zipWith (+) f (tail f) unless the dreaded monomorphism restriction is off, in which case you have to find some other way of making 'f' monomorphic, for example with ScopedTypeVariables: fibonacci = let f = fibonacci :: [a] in 0 : 1 : zipWith (+) f (tail f) (I guess examples like this are exactly the reason the monomorphism restriction exists). Tom