[Haskell-cafe] Re: develop new Haskell shell?

Mats Jansborg jansborg at mdstud.chalmers.se
Fri May 12 21:54:25 EDT 2006


"Brian Hulley" <brianh at metamilk.com> writes:

> Donn Cave wrote:
>> On Fri, 12 May 2006, Brian Hulley wrote:
>>> Udo Stenzel wrote:
>>>> I'd like one as a scripting environment, a bit like scsh, just
>>>> strongly typed and easier on the eyes.  Haskell as interactive
>>>> shell would be a nightmare indeed, having to type 'system "foo"'
>>>> instead of simply 'foo' for everyday commands just won't cut it.
>>>
>>> This seems to be your only objection. It might be solvable by making
>>> some rule that an identifier that's used in a value position would be
>>> automatically bound to a function/value found by instantiating to a
>>> binary in the file system if it's not already bound, and there would
>>> need to be some rules about how binaries would work to cooperate
>>> with the Haskell type system.
>>
>> What about the parameters - certainly there's little point in
>> relieving me of the bother of quoting a command name, if I have to
>> quote each parameter?
>
> My idea of a Haskell shell would be that everything in the computer
> would be visible as a strongly typed monadic value, so for example,
> instead of typing
>
>  $ ghc -c -O1 Main.hs
>
> ghc would appear in the shell as if it was a normal Haskell function
> with this type:
>
> ghc :: GHCOptions -> [FileName] -> Shell ()

I and a fellow student have implemented something along those lines. We
walk through the $PATH and write a small stub definition for each
program. This is then compiled and loaded using hs-plugins. The result
is that you can access for example ghc from the command line. The type
of the automatically generated functions are e.g.:

cat :: Program String String

which is the best type you can give without a lot of manual labour (it
really ought to be [Word8]). You can then combine programs (and standard
haskell functions) like so:

cat >|< map toUpper

where
(>|<) :: (Cmd c1, Cmd c2, Marshal t, Marshal i, Marshal o) => c1 i t ->
           c2 t o -> Command i o

and
instance Cmd Program ... 
instance Cmd (->) ..

So the interface is not monadic but more similar to arrow composition.
This is probably a bad idea since you need to use something like xargs
to run a command on each item in the input.

As others (Donn) have pointed out, having to write (in our syntax) e.g.

ssh -."l" #"jansborg" #"remote.mdstud.chalmers.se"

gets old really quickly for interactive use, so I don't think a haskell
shell is really useful other than for scripting. Basic job control and
tab completion for programs and files (but not normal haskell bindings)
is implemented. The code is available here:

http://www.mdstud.chalmers.se/~jansborg/haskal.tar.gz

but please note that it is not at all finished, likely quite buggy,
completely undocumented and not really well thought through.

/Mats



More information about the Haskell-Cafe mailing list