replacing guile with haskell?
Alastair Reid
alastair at reid-consulting-uk.ltd.uk
Fri Oct 17 15:08:06 EDT 2003
> I'm wondering what the possibilities are for replacing the use of guile
> with a haskell interpereter? I'd like to be able to embed a haskell
> interpereter (presumably hugs) withing my program, so that the input file
> could be a haskell program.
Do you want to embed Haskell code or to embed a Haskell interpreter?
Embedding Haskell code is supported by the ffi specification and, in
particular, by GHC which will give good performance and trustworthy numeric
results.
> Currently, my best (and only) idea is to make the input file a script with
> #!/usr/bin/env runhugs
> at the top (and compiling an interface module with ffihugs).
You might get a little more value out of the Hugs server interface which lets
you unload and reload modules, etc.
See hugs98/docs/server.{html,tex}.
The documentation on
http://www.reid-consulting-uk.ltd.uk/alastair/publications/hugs-server/
server.ps.gz
is an out of date version of this document but gives a reasonable overview.
Googling for "hugs server" will find you various articles about using this
API.
> There are a couple of issues with this. The first is that I've heard that
> hugs isn't intended for numerical work (which is what I'm doing). I'm not
> sure if this will be a problem, since hugs won't be doing any of the real
> work anyways.
It's hard to comment on this. Hugs numeric routines are a lot better than
when the original "don't use" advice was written - but people do complain
every now and then.
> The other is that according to the man page, it seems that hugs only
> supports ffi on x86, powerpc and sparc, which seems likely to be a show
> stopper. Since I'll need to run the code on supercomputers, I won't always
> have a choice of architectures, and at least support for POWER (maybe comes
> free with powerpc?) would be necesary--IBM SP machines are quite nice. In
> this regard, ghc seems worse than hugs (the thought of bootstrapping ghc on
> a supercomputer gives me the shivers), and nhc98 last time I looked didn't
> support 64 bit platforms.
It's only calling Haskell functions from C which is non-portable.
Unfortunately, I'd guess that's the bit you need!
Porting Hugs' ffi to a new platform is pretty easy for someone with assembly
code experience since you only have to write one function - albeit a tricky
one. Less if ghc has already been ported to that platform since we can steal
code from them :-) The code involved is the function 'mkThunk' in hugs98/
src/builtin.c
GHC is available for powerpcs so it's probably just the operating system that
will cause trouble.
I would guess that nhc is easy to port to 64 bit machines since (at least
some) C compilers provide flags to compile for 32-bits. But I could easily
be wrong...
[Note: both GHC and NHC will need pretty much the same assembly code magic
that Hugs needs.]
--
Alastair Reid www.haskell-consulting.com
More information about the Haskell-Cafe
mailing list