Re [Haskell-cafe] Vanishing polymorphism
David House
dmhouse at gmail.com
Wed May 9 11:52:30 EDT 2007
On 08/05/07, Matthew Sackman <matthew at wellquite.org> wrote:
> > :t let f r s = let g (fn::forall n . (Num n) => n -> n) = return (fn r, fn s) in (return negate) >>= g in f
Ah, I may have been off the mark earlier. I think the problem is due
to the fact that you can't pass higher-order polymorphic functions
around. I.e., the following is a classic example of something people
expect to work, but doesn't:
runST $ ...
runST is a rank-2 polymorphic function, and you're attempting to pass
it as a parameter to the ($) function, which doesn't work. I think
your problem is similar. Here's the module I used to investigate
goings on:
{-# OPTIONS_GHC -fglasgow-exts #-}
import Data.Complex
g :: (Num a, Num b, Monad m) => a -> b -> (forall n. Num n => n -> n)
-> m (a, b)
g r s fn = return (fn r, fn s)
f :: Maybe (Int, Complex Float)
f = return negate >>= g (4 :: Int) (1 :+ 2)
You're attempting to pass the rank-2 polymorphic function "g (4 ::
Int) (1 :+ 2)" as a parameter to (>>=), which doesn't work.
General point: couldn't GHC's error reporting be improved at times like these?
--
-David House, dmhouse at gmail.com
More information about the Haskell-Cafe
mailing list