News for hackers. Stuff that matters.
Re:Do notation considered harmful by HelloNurse on Wednesday April 29, 2020 @08:43AM (#23018389)
The do notation allows the reader to misunderstand code quite deeply, contorting sound, standard and relatively simple functional programming techniques and idioms into an obfuscated and deceptive syntax that looks like something it is not.
Re:Do notation considered harmful by tromp on Wednesday April 29, 2020 @10:35AM (#23019727)
It's just syntactic sugar for Monad functions >>= and >> How can that be deeply misunderstood?
Re:Do notation considered harmful by whlr on Wednesday April 29, 2020 @11:00AM (#23020067)
Because it looks imperative.
Re:Do notation considered harmful by pinopinopino on Wednesday April 29, 2020 @04:33PM (#23023908)
Do notation is jokingly called a programmable semicolon. True, it is often used to model imperative computations with it, so that is the association people have with it. Also people come mostly from imperative backgrounds and look, we can bind something to a value. Finally something I get! And that is fine, let them play around with it like that.

But if they look closer, they find out it is not really imperative. Why is there a difference between let and bind? Why can't I reassign values. And they start to use more exotic and also more interesting monads and boom the imperative feel goes away.

For example with the interesting LogicT[1] monad. Or what about the probability monad[2]? Or the continuation monad[3]? Or the reverse state monad[4]? How imperative are those really? It really depends how you use it. And I think it adds more to the magic, that you think it is just imperative code at first, because suddenly you can create code that behave very different under various monads that represent computation models. I think that is a cool thing about this confusion.

I understand that if you are a professional that needs to get work done, it can be annoying.

[1]https://hackage.haskell.org/package/logict [2]https://hackage.haskell.org/package/probability [3]https://hackage.haskell.org/package/mtl-2.2.2/docs/Control-M... [4]https://lukepalmer.wordpress.com/2008/08/10/mindfuck-the-rev...

Re:Do notation considered harmful by whateveracct on Wednesday April 29, 2020 @12:44PM (#23021230)
ah so if you don't actually know what you're doing it could mislead you
Re:Do notation considered harmful by tome on Wednesday April 29, 2020 @09:34AM (#23018890)
An example would be probably make your case stronger.
Re:Do notation considered harmful by jhomedall on Wednesday April 29, 2020 @11:10AM (#23020171)
This:

  do 
    x <- ["a","b","c"]
    y <- ["d","e","f"]
    return (x ++ y)
evaluates to:

  ["ad","ae","af","bd","be","bf","cd","ce","cf"]
Note that this is _not_ equivalent to:

  ["a", "b", "c"] ++ ["d", "e", "f"]
which would instead evaluate to

  ["a","b","c","d","e","f"]


The Python equivalent would be:

  [(a + b) for a in ["a", "b", "c"] for b in ["d", "e", "f"]]
Which evaluates to:

  ['ad', 'ae', 'af', 'bd', 'be', 'bf', 'cd', 'ce', 'cf']
Re:Do notation considered harmful by Raidion on Wednesday April 29, 2020 @12:28PM (#23021039)
As someone who does not program in functional languages, this really really helps clear up the article and surrounding discussion. Good stuff!
Re:Do notation considered harmful by dllthomas on Thursday May 07, 2020 @05:33PM (#23108634)
On the other hand, as someone with a bit of Haskell background, this doesn't even seem weird (except the use of String over Text).