[MLton-user] Extended Basis Library: Partial order concept

Geoffrey Alan Washburn geoffw at cis.upenn.edu
Tue May 8 07:47:10 PDT 2007


Vesa Karvonen wrote:
> I'm not sure whether one should use < or <= in PORDERED_CORE.  I would go
> for <.  This is probably mostly because that is what I got used to when
> working with the C++ STL.  I don't know if there is any technical reason
> to prefer one over the other.  In particular, it takes on average the 
> same
> number of operations to synthesize other relational operators from either
> < or <=:
>
>  a < b              a < b                 not (b <= a)
>  a > b              b < a                 not (a <= b)
>  a <= b        not (b < a)                     a <= b
>  a >= b        not (a < b)                     b <= a
>  a == b        not (a < b or b < a)            a <= b and b <= a
>  a != b             a < b or b < a        not (a <= b and b <= a)
>
> A semi-technical reason would be that < is one character shorter than <=
> and definitions using < therefore lead to a few characters shorter code.
> All other things being equal, shorter is better.
    While shorter is usually better, I'm not sure I agree in this case.  
At least I hypothesize that most times that someone would want to define 
a partial order, they would find it more natural to define it in terms 
of a reflexive, transitive, anti-symmetric relation, rather than a 
transitive, anti-symmetric relation.  For example, in one of my several 
structures that admits a partial order (but not a total order) is an 
ordering based upon subset inclusion.  Therefore, I could define

    val op <= = Set.isSubset

instead of

    fun x < y = Set.isSubset (x, y) andalso not (Set.==(x, y))

furthermore in some cases equality will be defined in terms of <= and 
therefore writing something like the above may be a little awkward.


-- 
[Geoff Washburn|geoffw at cis.upenn.edu|http://www.cis.upenn.edu/~geoffw/]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mlton.org/pipermail/mlton-user/attachments/20070508/44145c93/attachment.htm


More information about the MLton-user mailing list