[Haskell-cafe] Rank2Types and pattern matching

Yves Parès limestrael at gmail.com
Sun Jul 4 06:05:57 EDT 2010


That's it !
Indeed, you do not create a STRef yourself using a STRef data constructor,
you use the function:
newSTRef :: a -> GHC.ST.ST s (STRef s a)

Thanks.

2010/7/4 Dan Doel <dan.doel at gmail.com>

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100704/2ae874bf/attachment.html


More information about the Haskell-Cafe mailing list