
11 Dec
2006
11 Dec
'06
2:04 p.m.
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?