[Haskell-cafe] Problem on existential type.
Roel van Dijk
vandijk.roel at gmail.com
Fri Sep 4 03:12:41 EDT 2009
The only knowledge the type system has about a GridWidget is that it
contains /some thing/ which is a member of the WidgetClass typeclass.
So the only thing you can do with the thing inside the GridWidget is
to apply functions of the WidgetClass. It might be easier to see with
the Show class instead of your WidgetClass.
data GridWidget = forall w. (Show w) => GridWidget w
foo :: GridWidget -> String
foo (GridWidget w) = show w
foo $ GridWidget "hi there"
> "hi there"
foo $ GridWidget (3, 5)
map foo [GridWidget True, GridWidget 3.14159]
But 'show' is the only function you can apply to values inside of a
GridWidget because it is the only function of the Show class. The same
holds for you WidgetClass.
On Fri, Sep 4, 2009 at 8:13 AM, Miguel Mitrofanov<miguelimo38 at yandex.ru> wrote:
> Your data type GridWidget doesn't have a parameter, yet you use it like it
> has one.
>> data GridWidget = forall widget. (WidgetClass widget) => GridWidget widget
>> liftGW :: (GridWidget widget) -> (widget -> t) -> t
More information about the Haskell-Cafe