Imagine I have a data record with many fields:
data DataRecord = DataRecord {
field1 :: String,
field2 :: String,
...
} deriving (Show)
Is it possible to hide some fields from the deriving (Show)
or do have to implement my own show
function for DataRecord
?
Reason for my question: When I have cyclic dependencies between two data records both using deriving (Show)
the show
function would generate an infinite string.
The Haskell 2010 report mentions your cyclic dependencies as unsuitable case:
The derived
Read
andShow
instances may be unsuitable for some uses. Some problems include:
- Circular structures cannot be printed or read by these instances.
So you need to specify the instance by hand.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With