[Haskell-cafe] pattern match on forall'ed data

Corentin Dupont corentin.dupont at gmail.com
Thu Jul 21 07:51:05 UTC 2016


Hi Ivan,
I could use isNothing, but the data is forall'ed...
I tried but it doesn't work:

data SomeData = forall e. (Typeable e, Eq e) => SomeData e

isNothing' :: SomeData -> Bool
isNothing' (SomeData a) = case (cast a) of
   (a :: Maybe a) -> isNothing a

Could not deduce (Typeable a) arising from a use of ‘cast’

On Wed, Jul 20, 2016 at 11:21 PM, Ivan Lazar Miljenovic <
ivan.miljenovic at gmail.com> wrote:

> On 21 July 2016 at 02:30, Corentin Dupont <corentin.dupont at gmail.com>
> wrote:
> > I see....
> > The think is, I am interested to know if "e" is "Nothing", whatever the
> type
> > of Nothing is!
>
> Data.Maybe.isNothing ?
>
> >
> >
> >
> > On Wed, Jul 20, 2016 at 5:44 PM, Patrick Chilton <chpatrick at gmail.com>
> > wrote:
> >>
> >> It's because you're doing === Nothing and the type of the Nothing is
> >> ambiguous (Maybe a1).
> >>
> >> On Wed, Jul 20, 2016 at 5:18 PM, Corentin Dupont
> >> <corentin.dupont at gmail.com> wrote:
> >>>
> >>> Hi all,
> >>> I'm surprised this doesn't work:
> >>>
> >>> data SomeData = forall e. (Typeable e, Eq e) => SomeData e
> >>>
> >>> (===) :: (Typeable a, Typeable b, Eq a, Eq b) =>  a ->  b ->  Bool
> >>> (===) x y = cast x == Just y
> >>>
> >>> test :: SomeData' ->  Bool
> >>> test (SomeData' e) | e === Nothing = True
> >>> test _ = False
> >>>
> >>> It says
> >>>  Could not deduce (Eq a1) arising from a use of ‘===’
> >>>
> >>> How can I achieve something of the same effect?
> >>>
> >>> Thanks
> >>> Corentin
> >>>
> >>> _______________________________________________
> >>> Haskell-Cafe mailing list
> >>> To (un)subscribe, modify options or view archives go to:
> >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> >>> Only members subscribed via the mailman list are allowed to post.
> >>
> >>
> >
> >
> > _______________________________________________
> > Haskell-Cafe mailing list
> > To (un)subscribe, modify options or view archives go to:
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> > Only members subscribed via the mailman list are allowed to post.
>
>
>
> --
> Ivan Lazar Miljenovic
> Ivan.Miljenovic at gmail.com
> http://IvanMiljenovic.wordpress.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160721/5055b76e/attachment.html>


More information about the Haskell-Cafe mailing list