On Tue, Dec 25, 2007 at 08:11:34AM +0300, Konstantin Vladimirov wrote: > [haskell] > module TypeTrouble where > > class FirstClass a where > firstFunction :: (SecondClass b) => a -> b > > class SecondClass a where > secondFunction :: a -> Double > [/haskell] > > I need, the firstFunction of FirstClass types to return a value of a > SecondClass type. For example SecondData for FirstData, but for some > FirstClass ThirdData, some SecondClass FourthData, etc.
The problem, as is often the case, is that that which is unwritten does
not resolve in the way you expect and require it to.
FirstClass' true signature is
class FirstClass a where
firstFunction :: a -> forall b. SecondClass b => b
That is to say, any implementation of firstFunction must work for ANY
instance of SecondClass. But you want SOME, not ANY. And SOME
(normally notated exists tvar. tspec) is not supported in any known
dialect of Haskell. It's possible to get fairly close with GHC
Haskell's fundeps / type families:
-- fundep version
class SecondClass b => FirstClass a b where
firstFunction :: a -> b
-- type family version
class SecondClass (Cod a) => FirstClass a where
type Cod a :: *
firstFunction :: a -> Cod a
It is almost certainly possible to accomplish your goals within
standard Haskell, but the best approach is not obvious at the current
level of detail.
Stefan
signature.asc
Description: Digital signature
_______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
