If you want to use just Typeable, you can implement your own cast:
Extract the TypeRep of the thing in SomeData, get the TyCon, which is
the top-level constructor, i.e. Maybe without arguments, and compare it
with the TyCon from Maybe. If they match, you coerce the value to Maybe
() and use isNothing. While this is not completely safe, we do not
evaluate the thing we just coerced to (), and thus are safe, as Maybe
should have identical representation regardless of the type parameter.
isNothing' :: SomeData -> Bool
isNothing' (SomeData a) = tyCon == maybeTyCon
&& isNothing (unsafeCoerce a :: Maybe ())
where
tyCon = typeRepTyCon (typeRep (mkProxy a))
maybeTyCon = typeRepTyCon $ typeRep (Proxy :: Proxy (Maybe ()))
mkProxy :: a -> Proxy a
mkProxy = const Proxy
On 07/21/2016 09:51 AM, Corentin Dupont wrote:
> 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.mi...@gmail.com <mailto:
ivan.mi...@gmail.com>> wrote:
>
> On 21 July 2016 at 02:30, Corentin Dupont <
corenti...@gmail.com
> <mailto:
corenti...@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
> <
chpa...@gmail.com <mailto:
chpa...@gmail.com>>
>
Ivan.Mi...@gmail.com <mailto:
Ivan.Mi...@gmail.com>
>
http://IvanMiljenovic.wordpress.com