You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
comparable a b = isJust (compare a b)
leq a b =casecompare a b of { JustLT->True; JustEQ->True; _ ->False }
However, defining compare involves two calls to the interface:
compare a b =case (leq a b, leq b a) of
(True, True) ->JustEQ
(True, False) ->JustLT
(False, True) ->JustGT
(False, False) ->Nothing
This may be problematic if there is common work to be done for leq a b and leq b a. The pure interface does not allow sharing of this joint work.
For example, consider sets implemented by sorted lists. A call to leq a b = isPrefixOf a b would have worst-time complexity O(min(n,m)); but compare would just run in the same time. So, the interface with just leq gives a slow-down of factor 2 in the worst case.
The text was updated successfully, but these errors were encountered:
The interface for
PartialOrd a
has two methods:https://hackage.haskell.org/package/lattices-2.0.3/docs/Algebra-PartialOrd.html#t:PartialOrd
I think an interface as chosen in package
partial-order
allows for more efficient implementations:https://hackage.haskell.org/package/partial-order-0.2.0.0/docs/Data-PartialOrd.html#v:compare
From the latter, we easily define:
However, defining
compare
involves two calls to the interface:This may be problematic if there is common work to be done for
leq a b
andleq b a
. The pure interface does not allow sharing of this joint work.For example, consider sets implemented by sorted lists. A call to
leq a b = isPrefixOf a b
would have worst-time complexity O(min(n,m)); butcompare
would just run in the same time. So, the interface with justleq
gives a slow-down of factor 2 in the worst case.The text was updated successfully, but these errors were encountered: