2 ms·
In terms of pedagogy I think there's a valid argument that we shouldn't teach beginners about the do notation until they're comfortable with monads. Coming from
by alephu5 6y ago
In terms of pedagogy I think there's a valid argument that we shouldn't teach beginners about the do notation until they're comfortable with monads. Coming from an OO background they can grok typeclasses as interfaces quite easily, and the bind and return operations as special methods. It's probably better to use pure instead of return but that's another debate.
In the same way I never tell python beginners about list comprehensions, we just do pedestrian loops.
In both cases, as you get comfortable and learn more you'll naturally stumble across these features and a myriad of others. Once you can happily read and write both variants, it doesn't matter too much, it's really just a matter of taste. I sometimes combine both in a single expression doing stuff like this
do
x <- a >>= b
...
for x in (f(t) for t in ts if g(t)):
h(x)
- tome 6y ago> do x <- a >>= b ... Please at least keep everything flowing in the same direction! do x <- b =<< a ...