Prelude function suggestions
ariep at xs4all.nl
ariep at xs4all.nl
Thu Jul 29 17:41:34 EDT 2004
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
More information about the Libraries
mailing list