3 ms·
That's a good point. But it actually goes back to my previous point that we need to teach that multiple IO actions need to be sequenced together to guarantee pr
by yawaramin 9y ago
That's a good point. But it actually goes back to my previous point that we need to teach that multiple IO actions need to be sequenced together to guarantee proper order, hence you can't just map a print operation over a list of items--and in fact the type system prevents you from making that mistake.
As I mentioned before, I would stick to the do notation syntax sugar; there's really no need to bring the symbolic operators into this:
printElements [] = return ()
printElements (x:xs) = do
putStrLn x
printElements xs
- crimsonalucard 9y agodo notation sugars free variables which leads to more confusion and more complexity. It may not be idiomatic, but I avoid do notation for this reason. It's almost a backwards abstraction... if the functional style is really better... why create syntactical sugar to make haskell seem imperative? You guys are right on traverse or mapM though.
- yawaramin 9y agoYes, we have to walk a fine line here. The fact that do notation desugars to function calls in a complete deterministic way is nevertheless not easy to explain to learners. It's a judgement call but overall its benefits outweigh the drawbacks--IMO.