[Haskell-cafe] Explicitly calling syntactic equality on datatypes

Olaf Klinke olf at aatal-apotheke.de
Wed Sep 18 19:49:00 UTC 2019

IMHO Tom's suggestion is the way to go, because:

(1) The normalized values form a sub-set of the general ones. If you have just one data type for both, then you'll have no static guarantee of normalization, and this will lead to mistakes once you fail to track the normalize calls. 

(2) Since the normalized values are a sub-set, coercing a normalized value back into the super-type is cheap. 

(3) Two distinct types guarantee that you won't do the same work twice. Your proposal of (==) `on` normalize will re-calculate the normalization every time you call (==), if no memoization happens. 

(4) The existing machinery of the compiler suffices to do what you want. 

If you consider the two forms semantically equal then maybe the non-normalized form should be represented as a thunk. Isn't that what the ShowS type is about? 

Just my 2 cents. 

More information about the Haskell-Cafe mailing list