Prelude function suggestions

ariep at ariep at
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).


Arie Peterson

More information about the Libraries mailing list