Is there any particular reason FiniteMap (and hence Set) aren't instances of Ord? I realize it's "weird" to define a map to be ordered, but even if the Ord definition were in some sense "nonsensical", being able to have, for instance, Sets of Sets of things would be really nice. -- Hal Daume III "Computer science is no more about computers | hdaume@isi.edu than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume
On Wednesday 29 May 2002 02:58, Hal Daume III wrote:
Is there any particular reason FiniteMap (and hence Set) aren't instances of Ord? I realize it's "weird" to define a map to be ordered, but even if the Ord definition were in some sense "nonsensical", being able to have, for instance, Sets of Sets of things would be really nice.
I guess I talked about combinatorics of finite sets a while ago. heh ;)
--
Eray Ozkural (exa)
for instance, Sets of Sets of things would be really nice.
Sure. One could simply use lexicographic ordering (i. e. s1 `compare` s2 = setToList s1 `compare` setToList s2) or length-lexicographic ordering (for efficiency) ... = (cardinality s1, setToList s1) `compare` (cardinality s2, setToList s2) As you write, there seems to be no reason not to do this. An Ord instance should be a linear ordering, and the above are. -- -- Johannes Waldmann ---- http://www.informatik.uni-leipzig.de/~joe/ -- -- joe@informatik.uni-leipzig.de -- phone/fax (+49) 341 9732 204/252 --
I agree; the problem is that I fear that making my own instance by using setToList will be very inefficient (or at least much more so than an instance which actually looks at the tree structure). -- Hal Daume III "Computer science is no more about computers | hdaume@isi.edu than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume On Wed, 29 May 2002, Johannes Waldmann wrote:
for instance, Sets of Sets of things would be really nice.
Sure. One could simply use lexicographic ordering (i. e. s1 `compare` s2 = setToList s1 `compare` setToList s2) or length-lexicographic ordering (for efficiency) ... = (cardinality s1, setToList s1) `compare` (cardinality s2, setToList s2)
As you write, there seems to be no reason not to do this. An Ord instance should be a linear ordering, and the above are. -- -- Johannes Waldmann ---- http://www.informatik.uni-leipzig.de/~joe/ -- -- joe@informatik.uni-leipzig.de -- phone/fax (+49) 341 9732 204/252 --
On Wednesday 29 May 2002 02:58, Hal Daume III wrote:
Is there any particular reason FiniteMap (and hence Set) aren't instances of Ord? I realize it's "weird" to define a map to be ordered, but even if the Ord definition were in some sense "nonsensical", being able to have, for instance, Sets of Sets of things would be really nice.
Check this out. It was working for me last time I used it.
Comments welcome,
--
Eray Ozkural (exa)
(Re: Eray's code using FiniteMaps/Sets)
Comments welcome,
I'd suggest
show s = "mkSet " ++ show (setToList s) show fm = "listToFM " ++ show (fmToList fm)
That way you can easily paste the output of a program into your code back again, and you can easily tell the type of the `showed' object. Best regards, -- -- Johannes Waldmann ---- http://www.informatik.uni-leipzig.de/~joe/ -- -- joe@informatik.uni-leipzig.de -- phone/fax (+49) 341 9732 204/252 --
participants (3)
-
Eray Ozkural -
Hal Daume III -
Johannes Waldmann