3 ms·
The "awkward" Haskell line could be rewritten: mapM_ print ys
by dllthomas 11y ago
The "awkward" Haskell line could be rewritten:
mapM_ print ys
- Chris_Newton 11y agoYes, that would have been a better choice. Thanks.
- dllthomas 11y agoUsing sequence_ and map can be argued on the grounds that mapM_ is only recently visible in Prelude in GHC (and not so in the Haskell standard), but using it is probably more idiomatic and certainly clearer.
- Chris_Newton 11y agoI think both changes (mapM_ and print) are certainly clearer and probably more idiomatic today. Coincidentally, I wrote almost exactly your suggested line of code only yesterday for another project, but those simplifications didn’t occur to me as I was writing my earlier post, perhaps because I reached the original form via some edits to make all the examples produce equivalent output. I’d love to say I was just trying to be careful about portability in this case, but I’m afraid it was nothing so clever. :-)