Hacker News new | ask | show | jobs
by haxeny1 3872 days 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

(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/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-O...

data Ordering :: *

Constructors LT EQ GT

1 comments

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