[Haskell-cafe] Fwd: extending Do notation

Kim-Ee Yeoh ky3 at atamo.com
Tue May 20 18:34:28 UTC 2014


On Wed, May 21, 2014 at 12:45 AM, Miguel Mitrofanov
<miguelimo38 at yandex.ru>wrote:

> Actually, something like
>
> do ...
>     if <- checkCondition
>       then doReportSuccess
>       else doReportFailure
>
> as well as
>
> do ...
>     case <- generateResult of
>       Nothing -> ...
>       Just r -> ...
>

Yes, this looks like nice syntax sugar to me. And I gather that the recent
(to me, anyway) lambda-case and lambda-if have abated the incromulence:

https://ghc.haskell.org/trac/ghc/ticket/4359

Quote: "The motivating examples seem to be of the form

getArgs >>= case of
            [] -> error "No args"
            fs -> doit fs
"

So

do ...
    case <- generateResult of
      Nothing -> ...
      Just r -> ...

becomes

do
    generateResult >>= \case
      Nothing -> ...
      Just r -> ...

Nevertheless, upward and onward to an even finer imperative language!

-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140521/af35ba3e/attachment.html>


More information about the Haskell-Cafe mailing list