[Haskell-beginners] Bool -> a -> Maybe a, or something similar

Michael Xavier nemesisdesign at gmail.com
Sat Jun 18 05:37:22 CEST 2011


Hayoo seems to me to do a better job at type signature searching. A ton of
libraries seem to define a toMaybe function for this:

http://hackage.haskell.org/packages/archive/utility-ht/latest/doc/html/Data-Maybe-HT.html#v:toMaybe

That isn't built in though.

On Fri, Jun 17, 2011 at 8:24 PM, Tacit Sawk <tacit at kwasticat.com> wrote:

> **
> Hello!
>
> I tried Hoogle, but it didn't seem to have what I was after. I'm looking
> for something like this:
>
> > maybeWhen :: Bool -> a -> Maybe a
> > maybeWhen cond =
> >   if cond
> >      then Just
> >      else const Nothing
>
> Is there a builtin that has the above sort of behaviour? I suppose it can
> even be generalised:
>
> > maybeWhen :: (MonadPlus m) => Bool -> a -> m a
> > maybeWhen cond =
> >   if cond
> >      then return
> >      else const mzero
>
> Tacit
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>


-- 
Michael Xavier
http://www.michaelxavier.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110617/861eeccc/attachment.htm>


More information about the Beginners mailing list