
H4sh – Exposing the Haskell List library as a set of shell utilities - Mayeu
https://github.com/cpennington/h4sh
======
cies
I added it to a list that I maintain on the Haskell wiki, trying to sum up all
Haskell effort related to shell scripting:

[https://wiki.haskell.org/Applications_and_libraries/Operatin...](https://wiki.haskell.org/Applications_and_libraries/Operating_system#Haskell_shell_examples)

~~~
Mayeu
:+1:

------
xnyhps
I was going to post that I was happy to see a new project using hs-plugins,
but then I noticed:

> h4sh was written during a cold, but sunny weekend in August 2005.

hs-plugins looks so cool, but I'm afraid it's bit-rotten and abandoned. :(

~~~
cies
Here is a particular update of hs-plugins:

[https://github.com/Changaco/haskell-
plugins](https://github.com/Changaco/haskell-plugins)

------
kazinator
> take 100 data | map show.length | sort | reverse | head
    
    
       $ txr -t '[(opip get-lines (mapcar length) sort reverse)]' | head
       asdfasdf
       adsfas
       da
       sfa
       f
       sdfadsf
       asd
       asdf
       [Ctrl-D]
       8
       7
       6
       4
       3
       3
       2
       1
       0
    

Pattern for wrapping any list processing function as a command:

    
    
       $ mapcar()
       > {
       >    txr -t "[(opip get-lines (mapcar $@))]"
       > }
       $ mapcar length < /etc/motd
       63
       0
       43
       0
       28
       33
       0
       36
       42
       0
    

Bored now.

------
t0rb3n
How can you not name this 'hashell'?

~~~
Mayeu
[https://wiki.haskell.org/Applications_and_libraries/Operatin...](https://wiki.haskell.org/Applications_and_libraries/Operating_system#Haskell_shell_examples)
:)

~~~
t0rb3n
woah, that's a lot of shells ^^

------
amelius
Can it also make immutable copies (snapshots) of the filesystem?

~~~
gh02t
Doubt it. That's something done by the filesystem itself and doesn't really
belong in the shell. You can do it with btrfs or zfs though. LVM too.

~~~
amelius
But immutability is something I'd expect from a functional language/shell.

~~~
gh02t
It's not something I'd expect. A shell deals with plumbing together programs
and _files_ , which are an abstraction over the actual raw filesystem (which
is exposed by the kernel). For a shell to do true snapshots, it'd have to talk
to the underlying filesystem. In theory this is possible I guess, but then
your "shell" needs to be the compatible with the filesystem you're in, which
is a very weird situation.

IMO a much better way to go about it would be to encode filesystem operations
inside a monad. Then you could chain together filesystem operations to make up
some sort of transformation, then after it's built up apply the operations to
the real filesystem. It achieves something similar, but doesn't require any
sort of filesystem support.

You can manually get filesystem snapshots with say `btrfs subvolume snapshot`,
but the shell doesn't care about that. It doesn't ever deal with the
filesystem directly, it either asks the kernel to do something or calls a
program that asks the kernel to do something. To draw an analogy to databases
(which are usually essentially based on immutable data structures in the sense
that they're transactional), this would be like asking the postgresql command
line client to handle making sure that the actual database manipulations are
done transactionally. It doesn't quite make sense, that sort of business
belongs in the postgresql server (which would be the OS kernel in our analogy
here).

