The lazy Show instance for GHC.Generics.U1 is confusing.

David Feuer david.feuer at gmail.com
Thu Nov 24 02:55:25 UTC 2016


I was messing around in GHCi, exploring the generic representation of
a particular value. I tried out both

case testSequence of IxSequence x -> case from x of M1 (L1 y) -> y
and
case testSequence of IxSequence x -> case from x of M1 (R1 y) -> y

I was initially mystified to see that neither of these produced an
error. Surely, I thought, it can't be both L1 and R1! And indeed it
can't. But the Show instance for U1 is lazy, so the first test happily
printed out

M1 {unM1 = U1}

even though that is utter nonsense. I propose that U1 simply derive
the Show instance to avoid such peculiar behavior.

David Feuer


More information about the Libraries mailing list