[Haskell-cafe] Maybe to Either -- is there a better way?

Max Rabkin max.rabkin at gmail.com
Wed Aug 4 12:25:55 EDT 2010

On Tue, Aug 3, 2010 at 8:33 PM, Claude Heiland-Allen
<claudiusmaximus at goto10.org> wrote:
> {-# LANGUAGE TemplateHaskell, ScopedTypeVariables #-}
> import Language.Haskell.Djinn (djinnD)
> $(djinnD "maybeToEither" [t|forall a b . a -> Maybe b ->  Either a b|])
> main = print . map (maybeToEither "foo") $ [Nothing, Just "bar"]

This is very cool (as is Djinn itself), but for me the ideal syntax would be

maybeToEither :: a -> Maybe b -> Either a b
maybeToEither = $(derived)

Is something like this possible in TH? The splice would have to know
its declared (even inferred?) type.


More information about the Haskell-Cafe mailing list