Quick reminder to Future Dave, as I’m going to assume he’ll keep making the same mistake Past and Present Daves make.
When switching between my editor and GHCi REPL to test stuff out I often forget to add a deriving (Show, Eq)
or similar line to my data types. This normally occurs after I’ve just set up a bit of test data in the REPL, so if I just fix the data declaration and :reload
GHCi then my setup will be lost. We can use the StandaloneDeriving GHC extension to help here.
The following example is me playing around with some parsing stuff and forgetting to make ParseError
an instance of Show
(so it won’t print in the REPL), then using :set -XStandaloneDeriving
to fix this:
I’ve trimmed the orphan instance warning. In this case it should not be a problem as I’m just working around my forgetfulness. :)
We can also use this in real .hs
files if necessary via a language pragma ({-# LANGUAGE StandaloneDeriving #-}
) as described here.