On Wed, Jun 8, 2011 at 3:15 PM, Malcolm Wallace <[email protected]> wrote:
>
>> data Bar f a = Foo f => Bar {bar :: f a}
>
> The class context on the data constructor buys you nothing extra in terms of 
> expressivity in the language.  All it does is force you to repeat the context 
> on every function that uses the datatype.  For this reason, the language 
> committee has decided that the feature will be removed in the next revision 
> of Haskell.

You're thinking of a context on the type constructor, i.e.,

data Foo f => Bar f a = Bar { bar :: f a }


The reason the original code does not work is that the constructor
only adds Foo f to the class context during pattern matching. So, for
example, this works:

baz :: Bar f a -> a -> f a   -- n.b., no Foo context
baz (Bar _) = foo

But the code in the original post is trying to create a value of type
Bar f a, so the context is needed.

-- 
Dave Menendez <[email protected]>
<http://www.eyrie.org/~zednenem/>

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to