[Haskell-cafe] A 3 line program --> Reid, Don, Daniel

Philippos Apolinarius phi500ac at yahoo.ca
Sat Oct 24 22:03:35 EDT 2009

Thank you for your help. I am sure that you are right as to the cause of the problem.  However, I do not know what I should do to solve it. The Haskell program is generated by LaTeX macros.  It is useless to import System.IO.UTF8. I did it. The system keeps producing the same error.  What I need is to configure GHC to accept input from any editor, or text generating tool (like TeX). I suppose it is not very difficult to do it, since all other languages have it. I mean, Haskell is the only language  where I cannot type a common word like "façade" without running into trouble.

I will send you a slightly more complete program, so you can analyse the problem.  One has two programs in Tex, and an example.  The first file is haskell.gen and it defines the macro \haskell{}

% Store in file  haskell.gen
% Last change 2007-05-23


  \csname newwrite\endcsname\progPort
  \immediate\openout\progPort H\jobname.hs %
  \immediate\write\progPort{module H\jobname}%

  \ifx\progPort\UNDEFINED \haskellSetup\fi%

%end of file haskell.gen

The second file is hask.ell and it defines \eval{}.  It is slightly more complex than the previous one. Still, it is very simple.

% Store in file hask.ell
% Last change 2007-05-23


  \csname newwrite\endcsname\outPort % Port name
  \immediate\openout\outPort \jobname.hs %
  \immediate\write\outPort{import H\jobname}%
  \immediate\write\outPort{import IO}%
  \immediate\write\outPort{main= do  }%

  \ifx\outPort\UNDEFINED \evalSetup\fi
  \global\advance\evalFilecount by 1
    {  outh <- openFile "\evalAuxFile.ghc" { WriteMode;} }%
   \ifeof0 \immediate\closein0
   \else \input \evalAuxFile.ghc \fi}%

  \immediate\write\outPort{   hClose outh;}%
%end of file hask.ell

Below, there is an example of how to use the above macros. Store it in file tudin.tex.


\title{Calling Haskell from \LaTeX}
\author{Philippos Apolinarius}


\input haskell.gen
\input hask.ell % load \eval

\eval{ hPutStrLn outh "Hello, facade!"

\eval{ hPutStrLn outh (show (fat 6))

 fat n | n<1= 1
 fat n= n*fat(n-1)

In order to use these examples, do the following:

1 --- Apply latex to tudin.tex:

C:\hastex> latex tudin.tex

2 --- You have generated file tudin.hs and Htudin.hs. Execute tudin.hs:

C:\hastex> runghc tudin.hs

This action will generate two files: tudin-G-H-C1.ghc, and tudin-G-H-C2.ghc. There is one file for each instance of \eval{}.

3 --- If you run latex tudin.tex again, it will load these two files, and insert the results of the Haskell programs into the resulting pdf or dvi files.

C:\hastex> latex tudin.tex

 My friend has a lot of complex Clean libraries that she uses to generate postscript images of her designs.  The trouble is that she needs to compile Clean souce code generated by the two LaTeX macros.  SInce Clean needs two files per module (implementation module and definition module), the two LaTeX macros are quite complex.  Clean looks a lot like Haskell. Therefore, I believe that she will not have any difficulty in translating the code to Haskell. It is true that input/output is different in Clean and Haskell. However, input/output can be centered in the main function.  Unhappily she needs to write all those French, Swiss, Italian and Spanish names, like façade,  Antoní Gaudi,  Xenákes, etc. BTW, if you discover how to use strings in Haskell, one could write Haskell-café, instead of Haskell-cafe.

Looking for the perfect gift? Give the gift of Flickr! 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091024/3522ab83/attachment.html

More information about the Haskell-Cafe mailing list