[Haskell-beginners] Confused by type constraints
Daniel Fischer
daniel.is.fischer at googlemail.com
Tue Jun 7 11:03:37 CEST 2011
On Tuesday 07 June 2011, 10:51:00, Guy wrote:
> On 06/06/2011 17:31, Daniel Schoepe wrote:
> > On Sun, 05 Jun 2011 19:53:50 +0300, Guy<guytsalmaves-h at yahoo.com>
wrote:
> >> So in my original example, why isn't "instance Foo (Bar f)"
> >> destructing Bar - and making the constraint available?
> >
> > The "Bar" in "instance Foo (Bar f)" is a type constructor, not a data
> > constructor like the X in "s (X x)". Hence "instance Foo (Bar f)"
> > isn't really deconstructing anything, but applying the type
> > constructor Bar to f, whereas "s (X x)" matches a _value_ of type X.
> >
> > This might be a bit clearer if you name type and data constructors
> > differently, e.g.:
> >
> > data Bar f a = Foo f => MkBar { bar :: f a }
> >
> > Cheers,
> > Daniel
>
> Thanks, I (think I) understand your explanation, but ... why can't GHC
> infer that Bar must always be a Show, seeing as this is the only
> constructor?
undefined :: Bar f a
You get the Foo constraint from the constructor MkBar, but there is a value
which doesn't use the constructor, so you can't get it from the type alone.
More information about the Beginners
mailing list