Hell: A Haskell Shell
github.com
github.com
Move on, and look at these:
* http://hackage.haskell.org/package/Shellac
* http://hackage.haskell.org/package/pipes-shell
To be fair, you don't actually need them
lelf:~/srcs/hell$ reverse <$> pwd
"lleh/scrs/flel/sresU/"
But yes, right now it's just a bunch of renames.On a serious side note, it doesn't need pipes since the shell utilities are wrapped as function which are composable in Haskell.
ps: Haskell is such a Gloriously Happy Land, why make it "hell"?
===> scsh-0.6.7 is marked as broken: fails to install on amd64.
And I really wanted to play with it. Seems like I will have to help in Scsh reimplementation in Racket before I can do this. >> ls *.*
Vs. >> fmap (filter (isInfixOf ".")) ls'
No sale! ls "*.*"
couldn't be defined, e.g. ls = run . ("ls " ++)On "feel", it also feels like there should be a seamless syntactic protocol for post-POSIX shells, but I've yet to nail down how it would work. Straw-man requirements:
- Absolutely no special syntax to run programs
- Low-drama way to write "real code", i.e. native
scripting language syntax.
- Great integration via syntax, shell built-ins for
working in Unix-y pipeline.
- Replace powerful yet bizarre bash/zsh parameter
constructs with better native language tools.
By low-drama, think of the success of Markdown vs. HTML, TeX, etc. for markup. Not as powerful, but much easier to use for its use cases. IMO, this is the most powerful thing about the POSIX shells -- there's zero ceremony around running programs and dealing with I/O redirection. That's also the compromise, as things like quoting semantics get hairy. One way a post-POSIX shell could go is to retain this seamlessness while adding a touch more modality so that the worst problems of POSIX shells are eliminated. For example, multiple-quoting or re-quoting should never be needed, real data structures are both available and the default, etc.Anyhow, Hell looks like a fun experiment and sandbox. Enjoy!
I need to play more with TCL (the one non sh-like language I know that does this) but I think even it has some very strange features that grow out of treating ordinary text as strings.
Haskell's reputation exaggerates how this API was less powerful, or missing altogether, in early versions of the language. But its reputation is not what you write programs in.
Functional languages are all about keeping side effects under control so that you can tell what will and what will not change the state of the system. Think of it as incorporating awareness of program state into the type-system of the language.
Imagine a "normal" shell type chain:
ps -ef | grep 'elephant' | sort -nk2 >> logfile.txt
neither `grep`, nor `sort` should have any side effects, and if they do, then you have potential for weird bugs later on. (imagine your / is mounted read only, and sort has a side effect of writing everything to a temp file. now suddenly this otherwise sane looking chain stops working).In the command, you have a single input, and a single output (which has a specific mode, append). Those are the only IO functions which you've specified, but you have no guarantee that anything else will not make a mess of things.
The dream for "pure functional" shell scripting would be where the side effects are more obvious, and controllable, not to eliminate them.
(Not to mention checking locales to decide how to sort, checking if the output is terminal so that we can add colors, but only if the environment variable says so, and on, and on...)
The meme that Haskell can't do side-effects or that's its hard just won't die...
ls :: LsOptions -> IO Listing
instance ToString Listing where ...
instance Default LsOptions where def = LsOptions []
Now a single `ls` function can yield regular textual output, or the more specific Listing type can be used if you want to say, map over the files listed. toString <$> ls def
map toUpper . filesListed <$> ls def
The repl can automate the application of toString of course,
so the user can just enter `ls def`. Someone better at this than I could probably find a way to make the def parameter be optional, too.