I try to understand more deeply the Global Variables paradigm in Haskell, I took to work on https://kodu.ut.ee/~nestra/eng/splst11.pdf, as an exercise. First thing I did is rewrite some of the code in 2.1 - The library module : changed this
data family Var a :: * -- family declaration
class (Show l, Ord l) => Variable l where -- Class w/o method
to
class (Show l, Ord l, Eq l) => Variable l where
data Var l :: *
This should have the same meaning (my guess..) with the original code GHC complains further in compiling. Nevertheless the curious thing (for me) was that GHC complains if a class instance is not declared with an explicit deriving clause (my first attempt, it looks redundant:
instance Variable Integer where
data Var Integer = X | Y deriving (Show, Eq, Ord)
Questions:
- Isn't the derivation part of the inherited class "property" - I expected not to repeat this in the class instances.
- Is it possible to write in the same style as the paper w/o GHC complaining of a
Illegal instance declaration for `Variable (Var Int)'
on the line withinstance Variable (Var Int)
may be it's old style haskell (GHC98)? To avoid this I had to declare the class differently.