
29 Jul
2004
29 Jul
'04
9:41 p.m.
Henning Thielemann wrote:
Or say you want to implement a function
f :: Set (Maybe a) -> Maybe (Set a)
where the result is Nothing if any element of the Set is Nothing, and Just the set containing the Just values otherwise:
f s = toMaybe (not (Nothing `elementOf` s)) (mapSet fromJust s)
Tomasz Zielonka wrote:
How about using MonadPlus instance for Maybe? It seems a bit clearer to me.
You might write f as f = fromList . sequence . toList (where sequence is from Control.Monad) if there are 'toList' and 'fromList' functions, or maybe adapt 'sequence' to work with sets (or even an appropriate generalisation of lists and sets). Regards, Arie Peterson