4 ms·
That's exactly my point, though -- there's a standard module for POSIX integration, but it's not part of the language syntax itself. It's a subtle thing if you
by rcoder 18y ago
That's exactly my point, though -- there's a standard module for POSIX integration, but it's not part of the language syntax itself. It's a subtle thing if you don't do systems code often, but it becomes apparent after working with Perl for a while how much of it really is a domain-specific language for UNIX systems operations.
Haskell, as a general-purpose functional language, is always going to require just a few more keystrokes/lines of code to accomplish the equivalent system operations.
- eelco 18y agoSince I don't have any experience with doing system code in Perl, a small example would be nice.
- SwellJoe 18y agoI just talked about this in a JavaScript thread a few days ago as a reason JavaScript isn't quite ready to take the place of Ruby, Perl, and (kinda) Python on the server (though it probably will in the next year or two). The most obvious example in Perl is its file processing abilities (which are scary at times, and astonishingly beautiful in their conciseness--thus Perl is still the master of one-liners). Like Haskell, JavaScript also has some file-related libraries...but they're also off in the ghetto of a clunky library, as it has been (historically) in SmallTalk and Lisp. The difference between making a function call and using a core language feature can be subtle...but it's definitely a friction point (I hate using Python, despite its many positive aspects, for many system related tasks because regexes are in the ghetto, for example). So, here's a simple example: while (<>) { for $chunk (split) { # split on white space # do something with words } } This is the entirety of code for processing a file word by word (<> is a magic filehandle that slurps in files on the command line, and not really recommended in code used by untrusted folks...so in real world software there would be a bit more boiler plate, but not much...but it's a good example). Add in that regexes are first class citizens and a file handle in Perl can be a pipe or a network socket or stdin/stdout, and you have an exceedingly low friction environment for building system-related tools. That's not to say that Haskell can't overcome the fact that systems-level stuff isn't in the core language (most Perl additions in the past several years have also been in the form of libraries rather than more keywords and new syntax--at some point it makes sense to put things into libs rather than making the language bigger). I don't know enough about Haskell to say. But, I can say that I've been quite intimidated by the amount of code I need to write to do things that are one-liners or a handful of lines in Perl. I'm sure some of this is my lack of knowledge, and some of it is the lack of CPAN (in ten years, if Haskell is extremely lucky and extremely successful, it'll have a selection of libraries on par with CPAN of today). But I'm having fun tinkering, regardless. Worst case, I'll learn something new. I had a lot of fun with mjd's Higher Order Perl (which exhibits most of the major functional techniques, like currying, recursion, infinite iterators, memoization, etc. using Perl), so it'll be cool to "go native" for a while, and what better way to learn than by doing tasks I'm already familiar with in a new language...I may get some new perspective on how things can be done in Perl (since it has lots of functional features) and maybe I'll even find some new features that can be added to our products uniquely easily by introducing some Haskell code. An interesting source of perspective on what makes Perl magical for systems-related tasks would be a perusal of the perlvar manpage. Perl has a bunch of "magic" special variables, many of which are related to how Perl behaves when given files to munch on. Folks find this intimidating, but it's a source of great power, particularly for one-liners and pipes (Perl is very much of the UNIX culture, and Perl fits into a long line of pipes as well as grep or awk or sed). Of course, for many classes of problem you would never use most of those special variables. But, for systems related code, it's hard to beat. (I've tried. I spent a few years in a Python shop, and was constantly amazed by how verbose my code had to be in Python vs. doing the same task in Perl...it was also generally a lot slower. I like Python for lots of stuff, but systems tools aint exactly its strong suit. I may find the same is true of Haskell.)
- fusiongyro 18y agoTake 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.