[Haskell-cafe] Re: I hate Haskell's typeclasses

Ben Franksen ben.franksen at online.de
Fri Apr 25 17:03:38 EDT 2008


Jonathan Cast wrote:
> Type case is easy:
> 
>    genericShow :: Typeable a => a -> String
>    genericShow x = fromJust $ do
>                                  s <- cast x :: Maybe String
>                                  return s
>                       `mplus` do
>                                  n <- cast x :: Maybe Int
>                                  return (show n)
>                       `mplus` do
>                                  return "<unknown>"

This is a nice idiom I didn't know before. Definitely worth page on the wiki
or two.

Cheers
Ben



More information about the Haskell-Cafe mailing list