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

Ben Rudiak-Gould Benjamin.Rudiak-Gould at cl.cam.ac.uk
Fri May 12 10:57:09 EDT 2006


Brian Hulley wrote:
> Donn Cave wrote:
>> (cd /etc/stuff; cat * > result)
> 
> Well the problem here is that the command leaves you in /etc/stuff so 
> you have to remember this when you subsequently execute another command.

No it doesn't. The parentheses around the command sequence cause it to run 
in a subshell with its own private working directory.

> Well someone had to define the meaning of basename so if we make the 
> definition of renif similarly built-in the comparison is between
> 
>      ls >>= mapM_ (renif "txt" "hs")
> 
> and
> 
>     for a in *.txt; do mv $a $(basename $a .txt); done

This comparison is unfair because basename is a much more generic operation 
than renif. The Haskell code should be something like

     glob "*.txt" >>= mapM_ (\a -> mv a (basename a ".txt" ++ ".hs"))

> So the Haskell command is shorter, easier to read, and more re-usable, 
> because mapM_ (renif "txt" "hs") can be used anywhere that supplies a 
> list of files whereas "for a  in *.txt" doesn't make the source of the 
> list explicit. Do they come from the current directory? What if some 
> other list of files should be used?

This makes no sense. Bash has its own set of rules. The for statement 
iterates over a list, which in this case is generated by a glob. If you want 
something else, you use the appropriate construct. The body of the for loop 
is just as reusable as the corresponding Haskell code.

My reaction to this thread is the same as Donn Cave's: even after reading 
through the whole thread, I don't understand what a Haskell shell is 
supposed to be. It feels like people are more interested in capturing 
territory for Haskell than in solving any actual problem. For simple 
commands and pipes, the bash syntax is perfect. For anything nontrivial, I 
use some other language anyway. I long ago wrote a Perl script to do a far 
more general form of the renaming example you gave above. As far as I know, 
the only reason people write nontrivial /bin/sh scripts is that it's the 
only scripting language that's universally available on Unix systems. Even 
Perl isn't deployed everywhere. A Haskell shell is never going to be 
ubiquitous, and Haskell syntax is inferior to bash syntax for 99% of the 
command lines I type.

On the other hand, I'm entirely in favor of extending Haskell with functions 
like glob :: String -> IO [String]. That would be useful.

-- Ben



More information about the Haskell-Cafe mailing list