たとえば、次のデータ構造があるとします。
data Foo = Bool Bool | Int Int | Double Double
さて、これを行う簡単な方法はありますか:
foo :: Typeable a => a -> Foo
foo x = maybe (error "i dunno") id $
liftM Bool (cast x) `mplus`
liftM Int (cast x) `mplus`
liftM Double (cast x)
Typeable型でパターン マッチングの構文を作成することを考えた人はいますか?