Some of my data types in Haskell end up having quite a few records, for example
data MyData
= A Int Int String Float Int (Char, Char)
| B Int String Float (Char, String) String
and to check what type it is I end up writing functions like
isA :: MyData -> Bool
isA (A _ _ _ _ _ _) = True
isA _ = False
-- isB and so on
Now this gets cumbersome fairly quickly so I searched how to use derive or something similar to auto-generate those and I found this. However, the library proposed in that question seems to be out of date due to the introduction of ghc generics and the related generic-deriving library. I've taken a look at these but they seem to be very powerful and I don't quite know where to start.
So my question is: How can you (if possible) get around having to manually write isA and isB for MyData?
data MyData = A (Int, Int, String, Float, Int, (Char, Char)) | B (Int, String, Float, (Char, String), String)? - Elmex80sif isA x -- etc.check can generally be replaced with pattern matching onx(say, with acaseexpression). - duplode