[Haskell-cafe] TH instance code.

Claus Reinke claus.reinke at talk21.com
Tue Jun 22 12:21:26 EDT 2010


>I have below duplicate code, but i don't know how to use TH instance code.

>------------------------------> duplicate code start 
><------------------------------
>instance Variable PageType where
>   toVariant = toVariant . show
>   fromVariant x = fmap (\v -> read v :: PageType) $ fromVariant x

If this isn't an exercise to learn TH, you might also want to try
scoped type variables (7.8.7) to connect the 'read v' annotation
to the instance head:

http://www.haskell.org/ghc/docs/6.12.2/html/users_guide/other-type-extensions.html#scoped-type-variables

Claus




More information about the Haskell-Cafe mailing list