[Haskell-cafe] pattern match on forall'ed data
michaelburge at pobox.com
Wed Jul 20 17:40:16 UTC 2016
I've used toConstr from Data.Data when I only care which constructor a
value was constructed with. The specific type 'a' in 'Maybe a' is
effectively a phantom type for the Nothing constructor, which I haven't
used before. But it looks like it still works, so you could try comparing
Prelude Data.Typeable Data.Data> toConstr (Nothing :: Maybe Int) ==
toConstr (Nothing :: Maybe String)
Most of the time, you should be able to use a typeclass for this.
On Wed, Jul 20, 2016 at 9:30 AM, Corentin Dupont <corentin.dupont at gmail.com>
> I see....
> The think is, I am interested to know if "e" is "Nothing", whatever the
> type of Nothing is!
> On Wed, Jul 20, 2016 at 5:44 PM, Patrick Chilton <chpatrick at gmail.com>
>> 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?
>>> Haskell-Cafe mailing list
>>> To (un)subscribe, modify options or view archives go to:
>>> 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:
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe