On Sunday 04 July 2010 5:41:07 am Yves Parès wrote:
> Okay, I understand better, now.
> But I could never have guessed it just from the GHC error message.
> 
> Another question on the same code:
> 
> import Control.Monad.Identity
> 
> newtype SomeMonad s a = SomeMonad { unSome :: Identity a }
>   deriving (Monad)
> 
> newtype SomeType s = SomeType Int
> 
> runSomeMonad :: (forall s. SomeMonad s a) -> a
> runSomeMonad x = runIdentity . unSome $ x
> 
> foo :: SomeType s
> foo = runSomeMonad (return $ SomeType 42)
> 
> 
> According to what I read about ST, it should not compile because of 'foo'
> (hence the protection), well it does.
> What have I forgotten in my code?

The s in your SomeType isn't linked in any way to the variable quantified in 
the SomeMonad. You're producing:

  return $ SomeType 42 :: forall t. SomeMonad t (SomeType s)

and running it to get the SomeType s. You need something to tie them together, 
like:

  mkSomeType :: Int -> SomeMonad s (SomeType s)
  mkSomeType i = return (SomeType i)

and then hide the SomeType constructor, perhaps.

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

Reply via email to