[Haskell-beginners] How to avoid repeating a type restriction from a data constructor

gs voldermort at hotmail.com
Wed Apr 24 16:19:35 CEST 2013


Daniel Fischer <daniel.is.fischer <at> googlemail.com> writes:

> Removing the `Variable v` context from instance declarations is at least 
> tricky. I don't think you can do it at all here. For the context to become 
> available, you need to pattern-match, but in `newVar`, the `Source` appears 
> only as the result. Therefore you need the `Variable v` context to be able to 
> write
> 
>     v <- newVar a
> 
> Consequently, you can't have an
> 
> instance Variable (Source v) where ...
> 
> without context, and since `Variable b` is a superclass constraint on 
> `Bindable b`, you need something that guarantees that `Source x` (resp. 
> `BindingList x`) has a `Variable` instance.
> 
> 
> You're not pattern-matching on the constructor. I wrote that you have to do 
> that to make the context available:

Thank you, I understand now. So as far as removing redundant code is
concerned, this can't really be done? The instance declarations still need
the redundant context, and function definitions need a redundant
pattern-matching instead of a redundant context.





More information about the Beginners mailing list