[Haskell-cafe] Problem on existential type.

Ryan Ingram ryani.spam at gmail.com
Sat Sep 5 14:53:14 EDT 2009

On Thu, Sep 3, 2009 at 11:05 PM, Magicloud
Magiclouds<magicloud.magiclouds at gmail.com> wrote:
> data GridWidget = forall widget. (WidgetClass widget) => GridWidget widget
> liftGW :: (GridWidget widget) -> (widget -> t) -> t
> liftGW (GridWidget label) f = f label
> liftGW (GridWidget textView) f = f textView

The type signature on liftGW is wrong.  Also, as mentioned elsewhere,
the two matches overlap; the second case never gets called.

The correct type signature for "liftGW" is:

liftGW :: GridWidget -> (forall widget. WidgetClass widget => widget -> t) -> t

Note that the "f" passed in has to accept *any* widget type, so it's
possible that existential types aren't what you want.

  -- ryan

More information about the Haskell-Cafe mailing list