ghc command line evaluation

Benjamin Franksen benjamin.franksen at
Wed Apr 5 15:39:21 EDT 2006

On Wednesday 05 April 2006 20:32, Pedro Miguel Duarte wrote:
> I am writing a Java program with a call to a  Haskell module  M.hs,
> in order to evaluate some expression   expr.
> A very simple idea, which I got somewhere in the net,  is to create a
> Process object p  which executes a GHC command-line instruction:
> Process p = Runtime.getRuntime();
> p.exec( " ghc M.hs  -e \"expr\" " );
> This would be very simple, if it worked...
> My problem is that  expressions i want to evaluate involve
> strings, and GHC command-line  'ghc' misinterprets some special
> symbols when it  parses double quoted strings.
> For instance,
>      ghc -e  " reverse \"2<3\" "     gives an error!

Hmm. On my Linux machine (running zsh):

ben at sarun: .../play/ghc-e > ghc -e  " reverse \"2<3\" "

But now I see that you run 'p.exec' in Java which probably translates 
(more or less) to a 'exec' system call. 'exec' is not a shell, it 
cannot translate complex quotings and unquotings. I would try

p.exec( "/bin/sh ghc M.hs  -e \"expr\" " );

or something similar.


More information about the Glasgow-haskell-users mailing list