[Haskell-cafe] extending Do notation

Evan Laforge qdunkan at gmail.com
Tue May 20 20:22:08 UTC 2014


On Tue, May 20, 2014 at 1:02 PM, Kim-Ee Yeoh <ky3 at atamo.com> wrote:
>
> On Wed, May 21, 2014 at 2:47 AM, silvio <silvio.frischi at gmail.com> wrote:
>>
>> do print map (<-readFile) ["foo","bar"]
>
>
> The closest current Haskell can come to this is
>
> print =<< mapM readFile ["foo","bar"]
>
> And I agree that the manual effect typing, the requisite =<< and the mapM
> for map, can be a pain.

For an example that's harder to convert, I occasionally have something
like this:

f x
  | a && (b > 1 || (c && d)) && e = ...

Now if 'c' becomes monadic you have to rewrite the whole expression in
an entirely different (and much noisier) style.  Not just all the
lifting, but you can't use infix operators anymore.  It really does
feel like there are two languages (or dialects), with different idioms
and syntax.  You can translate between them without much complicated
effort, but it's still a manual translation.


More information about the Haskell-Cafe mailing list