Restricted Data Types: A reformulation
John Meacham
john at repetae.net
Tue Feb 7 21:01:49 EST 2006
On Tue, Feb 07, 2006 at 05:54:51PM -0800, Ashley Yakeley wrote:
> John Meacham wrote:
>
> >newtype Eq a => Set a = Set (List a)
> >singleton :: Eq a => a -> Set a
> >class Monad m where
> > return :: a -> m a
> >
> >instance Monad Set where
> > return x = singleton x
> >
> >okay, our goal is to make this typesafe.
>
> You shouldn't be able to, should you? Monad makes a promise that Set
> can't keep. In particular:
>
> returnid :: (Monad m) => m (a -> a)
> returnid = return id
>
> bad :: Set (a -> a)
> bad = returnid
however, (Set (a -> a)) is malformed. since a _requirement_ is that Set
can only be applied to a type with an Eq constraint so the instance you
try to do something like
returnid :: Set (a -> a) -- ^ static error! you need
returnid :: Eq (a -> a) => Set (a -> a)
the instant you introduce 'Set' you introduce the 'Eq' constraint. as
long as you are just working on generic monads then there is no need for
the Eq constraint.
John
--
John Meacham - ⑆repetae.net⑆john⑈
More information about the Haskell-prime
mailing list