[Haskell-cafe] fmap use

Tom Ellis tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk
Fri Dec 14 11:42:56 UTC 2018


On Fri, Dec 14, 2018 at 11:22:38AM +0000, Tom Ellis wrote:
> On Fri, Dec 14, 2018 at 11:49:45AM +0100, Damien Mattei wrote:
> > another question with Haskell, again with my database but that is again
> > related to Monads:
> 
> Damien, it's very hard to read your posts because they consist of snippets
> of code interspersed with commentary.  You'll probably get much better
> responses if you post single, very small, well-formatted examples of sample
> code.
> 
> Anyway, the ultimate answer to your query is "use do-notation".  Your
> getBS_WDS would be clearer written something like:

Ah, I see now why you were determined to use `fmap`.  Seph recommended it to
you

    I would avoid using do-notation at all until you’re a bit more comfortable
    with how monadic computations work, and how Haskell handles IO.  To someone
    used to imperative programming, it can be more confusing that helpful, as it
    allows you to write something that looks and feels a lot like imperative
    code but differs from it in crucial ways.  Get comfortable with using the
    monadic operators >> and >>= directly, and only then switch back to
    do-notation.  Or don’t—personally I prefer not to use do-notation at all.

    -- Seph Shewell Brockway

    https://mail.haskell.org/pipermail/haskell-cafe/2018-December/130367.html

I have to say I have completely the opposite position to Seph.  If you try
to write code in IO as a beginner without using do-notation you are in for a
world of pain.  Damien, I would suggest you write (very) small practice
programs using both Seph's advice and mine and see which style you prefer
and which helps you learn Haskell quicker.

Tom


More information about the Haskell-Cafe mailing list