

Bash is just a Monad - nullzzz
http://haskellrescue.blogspot.com/2011/11/bash-monad.html

======
mooism2
No, bash is not a monad. Really. This sort of article tends to obscure more
than it illuminates.

Bash runs the commands of a pipeline in parallel, so you don't get the
sequencing of side-effects that monads provide. You'd better off saying that
shell commands are plain functions (mapping stdin to stdout) than insisting
they're Kleisli arrows.

But to play along with the conceit: the pipe operator would translate into the
>=> operator, not >>=. The first command in the pipeline has a stdin, it's
just that usually the first command in a pipeline is one that ignores its
stdin.

~~~
nullzzz
First, I'd like to say that my intention in this posting was just to give a
rough analogy that would make monads a bit less scary for the non-haskellers.
I should have stated that more clearly though.

Hoever, I stand corrected. Bash executes the commands in a very different way
from the IO monad. Using pure functions like String -> String you'd get the
similar effect in Haskell, just like you suggested.

That that would of course disable all side-effects from the "links in the
chain". Which is in many cases desired, but that's not Bash though.

I guess I'd need to define a whole new Monad to emulate the way Bash operates.
I'm not saying you should emulate it though.

