Hi,

Perhaps I did not understand the question properly, but it looks very
straight forward :

oneOrNone x = fmap Just  x <|>  pure Nothing
it will have a type of oneOrNone :: (Alternative f) => f a -> f (Maybe a)
In fact, there is a function called "optional" in Control.Applicative[1]
which does exactly that.
Is this what you are looking for?

thanks,
Hemanth K

[1]
http://haskell.org/ghc/docs/6.12.2/html/libraries/base-4.2.0.1/Control-Applicative.html


On Fri, Aug 12, 2011 at 1:31 PM, C K Kashyap <ckkash...@gmail.com> wrote:

> Hello gentle Haskell folks,
>
> I happened to read "Beautiful code"'s chapter 1 today and found Brian
> Kerninghan's regex implementation. In it he only shows the * meta character.
> I can easily understand how + can be built but am having trouble with
> building ? (zero or one). I'd really appreciate it if some one could help me
> understand it.
>
> Regards,
> Kashyap
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to