<div dir="ltr">That's right, there are hints that my design is overly complex, I'm looking at simplifying it.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jul 21, 2016 at 11:50 AM, Patrick Chilton <span dir="ltr"><<a href="mailto:chpatrick@gmail.com" target="_blank">chpatrick@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">You also might want to consider whether this existential approach is correct to begin with. Could you just use a Maybe SomeData instead? Do you need the existential at all? <a href="https://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/" target="_blank">https://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/</a></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jul 21, 2016 at 10:48 AM, Corentin Dupont <span dir="ltr"><<a href="mailto:corentin.dupont@gmail.com" target="_blank">corentin.dupont@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>That's great, exactly what I need.<br></div>What do you mean by "just Typeable"?<br></div>Do you have another idea in mind?<br></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jul 21, 2016 at 10:23 AM, Jonas Scholl <span dir="ltr"><<a href="mailto:anselm.scholl@tu-harburg.de" target="_blank">anselm.scholl@tu-harburg.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">If you want to use just Typeable, you can implement your own cast:<br>
Extract the TypeRep of the thing in SomeData, get the TyCon, which is<br>
the top-level constructor, i.e. Maybe without arguments, and compare it<br>
with the TyCon from Maybe. If they match, you coerce the value to Maybe<br>
() and use isNothing. While this is not completely safe, we do not<br>
evaluate the thing we just coerced to (), and thus are safe, as Maybe<br>
should have identical representation regardless of the type parameter.<br>
<br>
isNothing' :: SomeData -> Bool<br>
isNothing' (SomeData a) = tyCon == maybeTyCon<br>
    && isNothing (unsafeCoerce a :: Maybe ())<br>
    where<br>
        tyCon = typeRepTyCon (typeRep (mkProxy a))<br>
        maybeTyCon = typeRepTyCon $ typeRep (Proxy :: Proxy (Maybe ()))<br>
        mkProxy :: a -> Proxy a<br>
        mkProxy = const Proxy<br>
<span><br>
<br>
On 07/21/2016 09:51 AM, Corentin Dupont wrote:<br>
> Hi Ivan,<br>
> I could use isNothing, but the data is forall'ed...<br>
> I tried but it doesn't work:<br>
><br>
> data SomeData = forall e. (Typeable e, Eq e) => SomeData e<br>
><br>
> isNothing' :: SomeData -> Bool<br>
> isNothing' (SomeData a) = case (cast a) of<br>
>    (a :: Maybe a) -> isNothing a<br>
><br>
> Could not deduce (Typeable a) arising from a use of ‘cast’<br>
><br>
> On Wed, Jul 20, 2016 at 11:21 PM, Ivan Lazar Miljenovic<br>
</span><span>> <<a href="mailto:ivan.miljenovic@gmail.com" target="_blank">ivan.miljenovic@gmail.com</a> <mailto:<a href="mailto:ivan.miljenovic@gmail.com" target="_blank">ivan.miljenovic@gmail.com</a>>> wrote:<br>
><br>
>     On 21 July 2016 at 02:30, Corentin Dupont <<a href="mailto:corentin.dupont@gmail.com" target="_blank">corentin.dupont@gmail.com</a><br>
</span><span>>     <mailto:<a href="mailto:corentin.dupont@gmail.com" target="_blank">corentin.dupont@gmail.com</a>>> wrote:<br>
>     > I see....<br>
>     > The think is, I am interested to know if "e" is "Nothing", whatever the type<br>
>     > of Nothing is!<br>
><br>
>     Data.Maybe.isNothing ?<br>
><br>
>     ><br>
>     ><br>
>     ><br>
>     > On Wed, Jul 20, 2016 at 5:44 PM, Patrick Chilton<br>
</span>>     <<a href="mailto:chpatrick@gmail.com" target="_blank">chpatrick@gmail.com</a> <mailto:<a href="mailto:chpatrick@gmail.com" target="_blank">chpatrick@gmail.com</a>>><br>
<span>>     > wrote:<br>
>     >><br>
>     >> It's because you're doing === Nothing and the type of the Nothing is<br>
>     >> ambiguous (Maybe a1).<br>
>     >><br>
>     >> On Wed, Jul 20, 2016 at 5:18 PM, Corentin Dupont<br>
</span><div><div>>     >> <<a href="mailto:corentin.dupont@gmail.com" target="_blank">corentin.dupont@gmail.com</a> <mailto:<a href="mailto:corentin.dupont@gmail.com" target="_blank">corentin.dupont@gmail.com</a>>> wrote:<br>
>     >>><br>
>     >>> Hi all,<br>
>     >>> I'm surprised this doesn't work:<br>
>     >>><br>
>     >>> data SomeData = forall e. (Typeable e, Eq e) => SomeData e<br>
>     >>><br>
>     >>> (===) :: (Typeable a, Typeable b, Eq a, Eq b) =>  a ->  b ->  Bool<br>
>     >>> (===) x y = cast x == Just y<br>
>     >>><br>
>     >>> test :: SomeData' ->  Bool<br>
>     >>> test (SomeData' e) | e === Nothing = True<br>
>     >>> test _ = False<br>
>     >>><br>
>     >>> It says<br>
>     >>>  Could not deduce (Eq a1) arising from a use of ‘===’<br>
>     >>><br>
>     >>> How can I achieve something of the same effect?<br>
>     >>><br>
>     >>> Thanks<br>
>     >>> Corentin<br>
>     >>><br>
>     >>> _______________________________________________<br>
>     >>> Haskell-Cafe mailing list<br>
>     >>> To (un)subscribe, modify options or view archives go to:<br>
>     >>> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
>     >>> Only members subscribed via the mailman list are allowed to post.<br>
>     >><br>
>     >><br>
>     ><br>
>     ><br>
>     > _______________________________________________<br>
>     > Haskell-Cafe mailing list<br>
>     > To (un)subscribe, modify options or view archives go to:<br>
>     > <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
>     > Only members subscribed via the mailman list are allowed to post.<br>
><br>
><br>
><br>
>     --<br>
>     Ivan Lazar Miljenovic<br>
</div></div>>     <a href="mailto:Ivan.Miljenovic@gmail.com" target="_blank">Ivan.Miljenovic@gmail.com</a> <mailto:<a href="mailto:Ivan.Miljenovic@gmail.com" target="_blank">Ivan.Miljenovic@gmail.com</a>><br>
>     <a href="http://IvanMiljenovic.wordpress.com" rel="noreferrer" target="_blank">http://IvanMiljenovic.wordpress.com</a><br>
<div><div>><br>
><br>
><br>
><br>
> _______________________________________________<br>
> Haskell-Cafe mailing list<br>
> To (un)subscribe, modify options or view archives go to:<br>
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
> Only members subscribed via the mailman list are allowed to post.<br>
><br>
<br>
<br>
</div></div><br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.<br></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.<br></blockquote></div><br></div>
</div></div></blockquote></div><br></div>