Hugs on Mac with CW6 ? ... and Haskell Graphics Lib?

Alastair Reid reid@cs.utah.edu
Thu, 7 Dec 2000 13:43:05 -0700


[Hugs Users removed from Cc list.  Messages about machine support
traditionally go to hugs bugs only.  Also, since hugs-bugs members are
supposed to be in hugs-users also, listing both is redundant.]

> Unfortunately, I could not find any Mac port of the Haskell
> Graphics Library.

I'm afraid there isn't one.
I have access to Unix and to Windows but not to a Mac.
(Also I don't know the Mac API.)

> Once I can get a plain Hugs working with CW 6, I'm hoping to
> try to figure out how to get it to interface to C, so I could
> supply something like the Haskell Graphics Library and link
> it in with Hugs.

Let me describe a few major steps in being able to write (or port) something
like the HGL for the Mac:

1) Get Hugs working (obviously)

2) Learn how to use one of the many Hugs Foreign Function Interfaces
   (FFIs) on the Mac.

   Choices:
   1) Directly modify builtin.c in the Hugs distribution.
      Tedious, error-prone, not recommended.
   2) Use GreenCard (http://www.dcs.gla.ac.uk/fp/software/green-card/)
      Stable, simple, limited level of support (none?)
      Requires you to find out how to build the Mac equivalent of
      shared libraries (Unix terminology) or DLLs (Windows terminology).
      (Looking at the Hugs sources, it appears that the answer is a .pef
      file and that someone has figured this out before - hopefully
      someone can send instructions in response to this message.)
   3) Use H/Direct (http://haskell.cs.yale.edu/haskellscript/hdirect.html)
      Easy to use if you already have a COM/IDL specification of the API
      you want to use.
      It's not clear whether it's still supported since the above page
      says the real home page is at:
http://www.dcs.gla.ac.uk/fp/software/hdirect
      which is a broken link.
   4) Use the FFI standard (http://haskell.cs.yale.edu/definition/ffi/)
      possibly in conjunction with some of the ffi tools/libraries that have
      come out such as Manuel Chakravaty's C->Haskell library
      (http://www.cse.unsw.edu.au/~chak/haskell/c2hs/)
      This is the preferred option.  There's just one small problem that I'll
      expand on below.
   5) Consult Haskell.org (http://haskell.org/libraries/#interfacing)

   Of these, I strongly recommend (4) with (2) as a second choice.
   The one small problem with (4) is that the official Hugs distribution
   does not support the FFI standard.  However, there is an unofficial
   Hugs distribution which does support it.  You can download it from
   my home page:

     http://www.cs.utah.edu/~reid/tmp/hugs98-ffi-03122000.tgz

   If you need to use foreign export dynamic, you will need to write
   a small machine code stub for your architecture.

3) Learn how to write simple graphical programs in C for the Mac.
   By simple I mean how to do things like:

     Hello World (where the text appears centred on a window).
     A simple drawing program that puts a black pixel on the
      screen if the mouse button is depressed.
     Responds to simple keyboard input.
     Responds to periodic and/or one-shot timers.

4) Use your choice of FFI to translate your simple C programs
   into Haskell.

5) Contact me for help on understanding the code in the
   Hugs Graphics Library (or for hints on how to produce
   something equivalent).
   (There's someone else trying to port the HGL to GHC so
   a 3-way discussion might arise.)

[The above list could take a while to work through and might be best tackled by
a team of people rather than just one person who is new to Haskell.  The HGL
and all the associated tools, libraries and techniques I had to develop to
write it was spread out over a period of about 5 years.]

>  -- would it be easier to work with GHC or HBC instead of Hugs?

It would be easier in that both have mature implementations of the ffi.
However, I don't know if either of them has been ported to the Mac yet.  If the
answer is no, I think it would be significantly easier to work with Hugs.
(This belief is based on lots of experience with Hugs and GHC.  I know very
little about HBC.)

--
Alastair Reid