3 ms·
Take a look at Don's reimplementation of some classic Unix tools as Haskell oneliners: http://www.cse.unsw.edu.au/~dons/data/Basics.html http://www.cse.unsw.edu
by fusiongyro 18y ago
Take a look at Don's reimplementation of some classic Unix tools as Haskell oneliners: http://www.cse.unsw.edu.au/~dons/data/Basics.html http://www.cse.unsw.edu.au/~dons/data/Basics.html.
The mere fact that interact lets you make a pure function into a Unix-style string -> string utility should show that you are exaggerating a bit.
interact (unwords . something . words)
handles basically your whole simple example.
Another simple example: capitalize every word of the input:
main = interact (unwords . (map (\(x:xs) -> Char.toUpper x : xs )) . words)
- SwellJoe 18y agoshow that you are exaggerating a bit No, it merely shows that I don't know Haskell--I didn't claim Haskell couldn't be as concise as Perl for this kind of thing...just that I don't know how to make it as concise. The link helps very much, thanks. (And, just so no one is misled, the same example could be done as a Perl one-liner, as well, using the magic variables I mentioned in the prior comment. I just figured I'd make it readable, since there are some anti-Perl bigots around just waiting for the chance to say, "I knew it! It's nothing but line noise!".) Also worth noting...I love that I can write code like the example you've shown in Perl (with some minor syntactic differences, but it does have first class functions and expressions as arguments), and the fact that Haskell seems to be entirely made up of code like that made it seem very appealing on first glance. That slurping a file can be written in Haskell in one line and some lib imports makes me...umm, I'm embarrassed to say...a little giddy. And it makes me wonder why I didn't start using Haskell sooner.