mercredi 28 janvier 2015

Haskell: Generically finding out whether the type of a value belongs to a type class or not

I want to write the isShowable function as part of this code.



data MaybeShowable = forall a . Show a => Showable a | Opaque
f :: (Data d) => d -> String
f x = case isShowable x of
Showable s -> show s
Opaque -> "<<OPAQUE>>"
isShowable :: (Data d) => d -> MaybeShowable
isShowable = ???


Is this possible by using the Data instance? If not, what is the best way to do it?






Aucun commentaire:

Enregistrer un commentaire