[Haskell-beginners] Confused by type constraints

Daniel Schoepe daniel.schoepe at googlemail.com
Fri Jun 3 15:55:39 CEST 2011


On Fri, 03 Jun 2011 16:04:05 +0300, Guy <guytsalmaves-h at yahoo.com> wrote:
> I have some code resembling
> 
> class Foo f where
> 	foo :: a -> f a
> 
> data Bar f a = Foo f => Bar {bar :: f a}
> 
> instance Foo (Bar f) where
> 	foo a = Bar $ foo a
> 
> GHC insists on Foo f => in the instance declaration. However, the definition of Bar guarantees that this will always be 
> the case. Why do I have to state this explicitly?

The constraints in the data type declaration only affect the
constructors. It's a known issue, unfortunately there doesn't seem to be
a way around it.

See also:
http://www.haskell.org/haskellwiki/Data_declaration_with_constraint

Cheers,
Daniel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110603/d1bb3792/attachment.pgp>


More information about the Beginners mailing list