Data.Set.findMin is a partial function
Henning Thielemann
lemming at henning-thielemann.de
Mon Dec 11 09:04:21 EST 2006
I'm using Set for algorithms which work this way:
while the set is non-empty
choose an element from the set
do something with that element
remove the element and some more that depend on it
However when I code this with Set.null and Set.findMin, I run into the
same trouble like with List.null and List.head, namely Set.findMin is a
partial function. I like to have a function like
choose :: Set a -> Maybe a
choose set = toMaybe (not (Set.null set)) (Set.findMin set)
toMaybe :: Bool -> a -> Maybe a
toMaybe False _ = Nothing
toMaybe True x = Just x
in Data.Set.
Opinions?
More information about the Libraries
mailing list