TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Functional programming and the death of the Unix Way

90 pointsby jemeshsuabout 13 years ago

17 comments

andolanraabout 13 years ago
The gist—as I understand it—is that Unix programs are essentially all equivalent to functions : ([String], TextStream) -&#62; (TextStream, TextStream) which limits how one can tie them together and causes a proliferation of text-processing tools (awk, sed, grep, cut, &#38;c &#38;c) which is not as elegant as functional programming. There are already some Unix command-line tools that work on structured data as mentioned, e.g. jsawk[1] is a tool inspired by awk whose scripting language is JavaScript and which works on JSON.<p>As an aside, I'd like to see people experiment with these concepts on an OS level while consciously targeting Xen or other virtualization systems. Already, Haskell can run barebones on Xen using HaLVM[2] and the successor to Plan 9, Inferno[3], <i>was</i> a virtual machine that could run either on bare metal or inside another OS. I can imagine an entirely new OS would meet some resistance—like Plan 9 did—but supplying an OS <i>intended</i> to be virtualized would let people experiment freely within their existing OS.<p>[1]: <a href="https://github.com/micha/jsawk" rel="nofollow">https://github.com/micha/jsawk</a> [2]: <a href="http://halvm.org/wiki/" rel="nofollow">http://halvm.org/wiki/</a> [3]: <a href="http://code.google.com/p/inferno-os/" rel="nofollow">http://code.google.com/p/inferno-os/</a>
评论 #3754812 未加载
评论 #3754710 未加载
judgej2about 13 years ago
Often times I’ll want to grab just one part of a command’s output to use for the input of another command. Sometimes I can use grep to do this, and sometimes grep isn’t quite flexible enough and sed is required. The regular expression required to get sed to do the right thing is often complex on its own, and of course the flags need to be set appropriately. If the data format is in columns, sometimes cut can be simpler.<p>Master Foo nodded and replied: "When you are hungry, eat; when you are thirsty, drink; when you are tired, sleep."<p>Upon hearing this, the novice was enlightened.<p>-- <a href="http://catb.org/~esr/writings/unix-koans/shell-tools.html" rel="nofollow">http://catb.org/~esr/writings/unix-koans/shell-tools.html</a>
评论 #3754329 未加载
icebrainingabout 13 years ago
TermKit[1] was a proposal that tried to fix some of those problems by adding two new channels (separating terminal in/out from stdin/stdout data pipes) and using MIME-types (particularly JSON) to the latter.<p>It got a lot of flack, and I don't agree with everything the author proposes, but I think that part could definitively be improved.<p>The problem, of course, is backward compatibility: even if you can reimplement and/or wrap the core utils, what about the thousands CLI programs in each distro's repository? You'll end up with an hybrid beast that doesn't really do anything well.<p>[1]: <a href="http://acko.net/blog/on-termkit/" rel="nofollow">http://acko.net/blog/on-termkit/</a>
dsrguruabout 13 years ago
So basically the author is saying:<p>The UNIX shell pipeline is really just a functional programming language whose functions can only operate on strings. Think how much more powerful, concise, readable, etc. it would be if other data types were supported.<p>I agree. I don't even think this requires changes at the OS level. Newlisp and Racket's shell attempt might be clunky, and Clojure certainly isn't ready for quick-and-dirty scripts, but it shouldn't be too hard to implement such a language if shell replacement is its main purpose.
评论 #3756115 未加载
评论 #3755842 未加载
jes5199about 13 years ago
I had an idea to write Clojure parsers for the standard unix command line tools that translates the output into s-expressions.<p>I got too frustrated - on the one hand, Clojure's slow start up time meant it was no fun to use in a simple pipe<p>and on the other hand, even the simplist unix util has surprisingly complicated behavior. Like `wc` - it outputs three columns of numbers, right? Well, unless it knows filenames, which go in a fourth column. Or unless you pass it flags, which can turn any set of the number columns on and off. And then I thought, wait, what happens if you make a file which has leading whitespace in the name - it turns out it only outputs a single space in front of the filenames, so any whitespace after that is part of the name.<p>Which lead me to the conclusion: unix tools aren't actually simple - they are actually really complicated, but you can construct a happy-path of simplicity for most use cases<p>and functional languages are still monolithic when it comes to interacting with the outside world. Maybe someone will make a service I can run in the background that will run my command-line clojure scripts in a pre-warmed JVM, but that's not a piece of technology that <i>I</i> want to try to write.
评论 #3755499 未加载
评论 #3755482 未加载
Ralithabout 13 years ago
&#62; I’m not advocating a return to Lisp machines here. We tried that and it didn’t work. Symbolics is dead, and no one even gave a eulogy at that funeral.<p>The hell? Lisp machines were awesome. I thought it was well known that they failed partly for political reasons, and partly because Symbolics was absolutely horrendous at business.<p>The only failing I'm aware of was the lack of multi-user support, which wasn't particularly unusual for era, and even now we don't have anything which can compare to their high points.
msutherlabout 13 years ago
Dataflow environments like PureData, Max/MSP, Quartz Composer and vvvv are very much like 2D GUI-driven shells that handle various data types. Max/MSP was, at least, explicitly conceived as a sort of UNIX for multi-media. After working with such tools for years, I must say that the tools the professional programmers use seem comparatively quite primitive in many ways (though much more advanced in others). A graphical environment that utilized the same sort of dataflow model, but with a more general intended audience, more extensible architecture and some concepts from functional programming would have the power to really change how programming is done.
geophileabout 13 years ago
The Unix Way, but piping python objects instead of text: <a href="http://geophile.com/osh" rel="nofollow">http://geophile.com/osh</a>.
评论 #3755863 未加载
why-elabout 13 years ago
Steve Yegge's The problem of emacs goes over some of issues discussed here, although it focused on text processing.<p><a href="https://sites.google.com/site/steveyegge2/the-emacs-problem" rel="nofollow">https://sites.google.com/site/steveyegge2/the-emacs-problem</a>
fpgeekabout 13 years ago
It sounds like the OP wants scsh (The Scheme Shell): <a href="http://www.scsh.net" rel="nofollow">http://www.scsh.net</a>
Drbbleabout 13 years ago
Try Powershell / Monad for Windows. It even solved Haskell's problem of Monad needing a name change :-) <a href="http://en.m.wikipedia.org/wiki/Windows_PowerShell" rel="nofollow">http://en.m.wikipedia.org/wiki/Windows_PowerShell</a>
ggchappellabout 13 years ago
... and the evolution can continue along the same lines as Unix. I think I'll write a Haskell function that takes two strings and returns a string. The first string is a program in a new language I'll invent. The second is the input to the program, and the return value is the output of the program.<p>Maybe I could call it "herl".<p><pre><code> herl :: String -&#62; String -&#62; String</code></pre>
dravenabout 13 years ago
This article reminded me of something I read about the Unix model vs the lisp model. I managed to track it down, it's a comp.lang.lisp posting by Erik Naggum.<p><a href="http://www.xach.com/naggum/articles/3245983402026014@naggum.no.html" rel="nofollow">http://www.xach.com/naggum/articles/3245983402026014@naggum....</a><p>The interesting part is the 3rd paragraph of the answer.
andrewflnrabout 13 years ago
I wonder, does this mean we actually want types as metadata on our shell commands? Type of args, type of stdin, type of stdout, or whatever we decide to call them?<p>All apps would have to speak a single, more complicated language and we would have to do more explicit translation but it might work out better.
评论 #3754814 未加载
szanyabout 13 years ago
Conal Elliott did something like this with Tangible Functional Programming.
peedyabout 13 years ago
True. However, about the issue that triggered this chain of thought, did you consider using the `cut` utility along with `grep` ?
vdmabout 13 years ago
Further reading: <a href="http://pinboard.in/t:functional/t:unix/" rel="nofollow">http://pinboard.in/t:functional/t:unix/</a>