[Haskell-cafe] Problem with JHC

Philippos Apolinarius phi500ac at yahoo.ca
Wed Nov 11 07:32:05 EST 2009

Hi, John.
I am trying JHC in a small embedded system (Medical instruments). The software is written in Clean, and I am translating to Haskell. You may want to take a look at my page:


I am writing because I found something in JHC that smells like a bug. The program compiles without a single complaint both in GHC and JHC, but the resulting binary file does not work in JHC. I wrote a simplified example so you can spot the problem easily. The original program is used to design and simplify digital circuits for sensors (capnograms, electrocardiograms, electroencephalograms, electromyograms, and temperature). It seems that JHC is not able to deal with the trees representing the circuits. Here is a very small program. All it does is to read a tree and show it:

{- file: tree.hs -}
{- compile: jhc tree.hs -dc -o jtree }
import System (getArgs)
import System.IO
import IO
data Op = AND | OR | NOT deriving (Show, Read)
data Tree= L Int | T Op [Tree] deriving (Show, Read) 
main= do
  putStrLn "Give me a tree:"
  s <- getLine
  let xx= read s
  putStrLn (show (xx::Tree))

Here is what happens when I try to run it:

philip at desktop:~/jhctut$ ./jtree
Give me a tree:
T AND (L 1, L 2)

jtree_code.c:2670: case fell off

It seems that the problem is in the Read class, since it works if I use the Show class only:

import System (getArgs)
import System.IO
import IO
data Op = AND | OR | NOT deriving (Show, Read)
data Tree= L Int | T Op [Tree] deriving (Show, Read) 
main= do
  putStrLn "Give me a tree:"
  s <- getLine
  let xx= T AND [L 1, L 2]
  putStrLn (show (xx::Tree))

I hope you can fix it.

--- On Wed, 11/11/09, John Meacham <john at repetae.net> wrote:

From: John Meacham <john at repetae.net>
Subject: Re: [Haskell-cafe] Opinion about JHC
To: haskell-cafe at haskell.org
Received: Wednesday, November 11, 2009, 1:37 AM

On Tue, Nov 10, 2009 at 07:41:54PM -0800, Philippos Apolinarius wrote:
> I discovered a Haskell compiler that generates very small and fast
> code. In fact, it beats Clean. It has the following properties:

Excellent. that was my goal ;)

> 1 --- One can cross-compile programs easily. For instance, here is how I generated code for Windows:
> jhc --cross -mwin32 genetic.hs -o genetic

Yup. This was a major goal. compiling for iPhones and embedded arches is
just as easy assuming you have a gcc toolchain set up. (at least with
the hacked iPhone SDK.. I have never tried it with the official one)

> 2 -- It seems to be quite complete.
> 3 -- However, it often compiles a file, but the program fails to run.
> I have the following questions about it:
> 1 -- How active is the team who is writing the JHC compiler?

Hi, I am the main contributor, but others are welcome and several have
made signifigant contributions. Development tends to be spurty. A lot of
work will get done in a short amount of time, this generally corresponds
to when an external contributor gets involved and the back and forth
helps stimulate patches on my part to complement theirs.

Although I have not been able to devote a lot of my time to jhc in the
past, hopefully this will change in the not to distant future and I will
be able to work on it full time. 

> 2 -- Is it complete Haskell? The author claims that it is; it compiled
> all programs that I wrote, but that does not mean much, because my
> programs are quite simple.

It does Haskell 98 and several extensions, which is pretty much what GHC
does. However, it does not implement the same set of extensions as GHC
so this causes issues as a lot of people use GHC extensions extensively. 

I plan on supporting all of Haskell' of course, and the popular GHC
extensions to help compatibility. Not all are implemented. 

> 3 -- Why the Haskell community almost never talks about JHC?

Part of it is that I am not very good at advocacy. I don't always
post announcements on the main haskell lists figuring the interested
parties are on the jhc list already. I do try to make jhc good, fast,
and usable, I always hoped someone better at advocacy than me would join
the project :) In truth, I think the spurty nature of development also
affects this, the list will be quite for a long time with a flurry of
development lasting a few weeks occasionally inspiring some discussion
in the other groups.

In any case, I am glad you liked what you found! please join the mailing
list for jhc if you are interested in its development or using it.


John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/
Haskell-Cafe mailing list
Haskell-Cafe at haskell.org

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/20091111/ba567d2c/attachment-0001.html

More information about the Haskell-Cafe mailing list