Re: [Haskell-cafe] Explicitly calling syntactic equality on datatypes

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. Olaf

(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.
I think this summarizes why we are thinking different things. I realize that "normalization" is a strong term, but do remember I was using this as an example (in my real example it is a form of normalization as well, though). The main thing is that, normalization or however you call it is *not* a main feature of my program. At least not right now. If it were, I'd agree with you that two separate types would be the way to go, and it might in the future. But, it is conceivable that this process is just a way to check equality, and that small operations that are not omnipresent in the rest of the program to be performed before syntactic equality is a pretty usual situation when checking equality for certain types. Therefore, forcing the user to re-implement syntactic equality every one of those times, specially when the compiler already knows how to do this, seems weird. In short, I agree with you that if the concept of normalization is important, separating the types is the right way to go. But this was not the main focus of my original post. I was more interested in saying: there is a small unimportant operation to be performed before checking equality, and thi sis forcing me to reimplement the entire thing. Thanks, Juan. -- The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336.
participants (2)
-
Juan Casanova
-
Olaf Klinke