[Haskell-cafe] Is there a way to generate instances from the GHCi REPL?

Artyom yom at artyom.me
Thu Feb 4 22:09:19 UTC 2016

If your instance-generating function is defined in an external module, 
you can use it in GHCi like this:

|-- Enable TH > :set -XTemplateHaskell -- Import modules (e.g. Aeson) > 
import Data.Aeson.TH > import Data.Aeson -- Define the type for which 
I'm going to generate instances > data X = X {x :: Int} -- Derive the 
instance Prelude Data.Aeson.TH> data Dummy; deriveJSON defaultOptions 
''X -- Check that it works > toJSON (X 1) Object (fromList [("x",Number 
1.0)]) |

(More about the |data Dummy| trick here: 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160205/a0e079fb/attachment.html>

More information about the Haskell-Cafe mailing list