[Haskell-cafe] ANN: HSH 1.2.0

David Roundy droundy at darcs.net
Sat Mar 3 11:25:03 EST 2007


On Sat, Mar 03, 2007 at 08:38:57AM -0600, John Goerzen wrote:
> I'm pleased to announce HSH 1.2.0.  Since version 1.0.0 was announced a
> few days ago, there have been some improvements:

How about -||- as an alias for something like `catch` $ \_ -> ? Or I'm not
sure the best design, in the sense of how you want to treat booleans.
e.g. 

This would allow simple shell-like error handling in pipes, using
exception-throwing as pipes:

sh:

echo "hello world" | grep z || echo "there is no z"

hsh:

run $ echo "hello world" -|- "grep z" -||- echo "there is no z"

I find this sort of idiom helpful in shell scripting.  The catch is that
you would probably have to treat the return code of grep as an exception,
which often isn't what you want.  And, of course, this wouldn't work at
all with your haskell grep, unless you change it to throw an exception on
failure to match (which seems ugly).


Another suggestion: might it be possible to move ShellCommand somehow more
directly into the IO monad? It'd be really nice if we wouldn't need the
"run $" on every line of a hsh script, and it seems like if you made
something like (and I don't believe it could be this simple)

(-|-) :: (ShellCommand a, ShellCommand b, RunResult c) => a -> b -> c

and then created an instance of ShellCommand for a RunResult, maybe you
would only need run when there's no pipe going on?

i.e. I'd like to be able to see

do l <- "echo hello world" -|- length
   rnd <- "cat /dev/urandom" -|- take l
   run $ "echo " ++ (concatMap tohex rnd)
 where tohex _ = "hex"

Yes, this code is stupid and could be simplified, but hopefully you can see
what I'd like: to be able to mingle your hsh ShellCommands right into the
IO monad.

I'm afraid that to work properly, this might require defaulting on the
ShellCommand or RunResult classes.  If so, it might be a good example to
guide the Haskell' discussion of defaulting.  I intentionally wrote the
above example so the typechecker could determine the result of each line,
because I use them... except for the last, which it'll bomb on, and
currently needs to be written as runIO.  But defaulting would be far
cleaner...
-- 
David Roundy
http://www.darcs.net


More information about the Haskell-Cafe mailing list