4 ms·
I was about to refute your argument by proposing creating a union type. Here is a relevant reference: https://realworldocaml.org/v1/en/html/functors.html https
by haxeny1 11y ago
I was about to refute your argument by proposing creating a union type. Here is a relevant reference:
https://realworldocaml.org/v1/en/html/functors.html https://realworldocaml.org/v1/en/html/functors.html
(This idiom is a bit of a historical error. It would be better if compare returned a variant with three cases for less than, greater than, and equal. But it's a well-established idiom at this point, and unlikely to change.)
Eiffel is similar to ocaml :
http://www.infor.uva.es/~felix/referencia_smart_eiffel/libraries/string.html http://www.infor.uva.es/~felix/referencia_smart_eiffel/libra...
Does anyone know the advantages of the above signature over the Haskell alternative? Because this seems to be more obvious and easier to read. So there are more than one language guilty of using a ternary operator for compare.
Haskell does define the appropriate constructors, rightly so:
https://hackage.haskell.org/package/base-4.8.1.0/docs/Data-Ord.html#t:Ordering https://hackage.haskell.org/package/base-4.8.1.0/docs/Data-O...
data Ordering :: *
Constructors
LT
EQ
GT
- mercurial 11y ago> Does anyone know the advantages of the above signature over the Haskell alternative? Historical reasons, mostly. The only practical advantage I can imagine is that it's a bit shorter to implement a reverse comparison, since you just multiply by -1.