20 Dec 11:46
Dynamic typing of polymorphic functions
From: <oleg <at> okmij.org>
Subject: Dynamic typing of polymorphic functions
Newsgroups: gmane.comp.lang.haskell.cafe
Date: 2007-12-20 10:47:51 GMT
Subject: Dynamic typing of polymorphic functions
Newsgroups: gmane.comp.lang.haskell.cafe
Date: 2007-12-20 10:47:51 GMT
Alfonso Acosta wrote: > mapSY :: (Typeable a, Typeable b) => (a -> b) -> Signal a -> Signal b > mapSY f (Signal primSig) = Signal (PrimSignal (MapSY (toDyn f) primSig)) > > The following process would be really useful but its compilation > obviously fails: > > mapSnd :: Signal (a, a) -> Signal a > mapSnd = mapSY snd > > > Could not deduce (Typeable a) from the context () arising from a > use of `mapSY' > Possible fix: > add (Typeable a) to the context of the type signature for `mapSnd' It seems the compiler's complaint is reasonable. The signature of the mapSY function says that mapSY may only be applied _provided_ that type variables 'a' and 'b' are instantiated to the types that are members of Typeable. That is, mapSY has a condition on its use. When you write > mapSndInt :: Signal (Int, Int) -> Signal Int > mapSndInt = mapSY (snd :: (Int, Int) -> Int) the condition is satisfied: 'a' and 'b' are instantiated to Int, and Int is a member of Typeable. The definition of mapSnd has no constraint. The compiler is upset: mapSY requires a condition, and(Continue reading)
RSS Feed