Hi,<div><br></div><div>Perhaps I did not understand the question properly, but it looks very straight forward :</div><div><br></div><div>oneOrNone x = fmap Just  x &lt;|&gt;  pure Nothing</div><div>it will have a type of oneOrNone :: (Alternative f) =&gt; f a -&gt; f (Maybe a) </div>
<div>In fact, there is a function called &quot;optional&quot; in Control.Applicative[1] which does exactly that.</div><div>Is this what you are looking for?</div><div><br></div><div>thanks,</div><div>Hemanth K</div><div><br>
</div><div>[1]<a href="http://haskell.org/ghc/docs/6.12.2/html/libraries/base-4.2.0.1/Control-Applicative.html">http://haskell.org/ghc/docs/6.12.2/html/libraries/base-4.2.0.1/Control-Applicative.html</a></div><div><br></div>
<div><br><div class="gmail_quote">On Fri, Aug 12, 2011 at 1:31 PM, C K Kashyap <span dir="ltr">&lt;<a href="mailto:ckkashyap@gmail.com">ckkashyap@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hello gentle Haskell folks,<div><br></div><div>I happened to read &quot;Beautiful code&quot;&#39;s chapter 1 today and found Brian Kerninghan&#39;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&#39;d really appreciate it if some one could help me understand it.</div>

<div><br></div><div>Regards,</div><div>Kashyap</div>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br><br clear="all"><br>
</div>