On 9/15/06, Vivian McPhail <[EMAIL PROTECTED]> wrote:

class Forkable a where
    fork :: String -> a -> a -> a

...
{-
instance (Monad m, Forkable (m a), Forkable b) => Forkable (m a -> b) where
    fork n a1 a2 a = do
                     a' <- a
                     fork n (a1 $ return a') (a2 $ return a')
-}


Let's do manual type checking.
First, fork :: Forkable a => String -> a -> a -> a
So for Forkable (m a -> b)
 fork :: String -> (m a -> b) -> (m a -> b) -> m a -> b
Then
 fork n a1 a2 a :: b
But you define it as
 fork n a1 a2 a = do {...}
So it should be of type Monad t => t a, not just any `b'.

Instead, you can define
 instance (Monad m, Forkable (m b)) => Forkable (m a -> m b) where
   ...

Note that to compile it you also need -fallow-undecidable-instances
and -fallow-overlapping-instances.

--
Tolik
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to