[jhc] Performance of lazy-lists

Henning Thielemann jhc at henning-thielemann.de
Sat Nov 20 09:49:47 EST 2010

On Sat, 20 Nov 2010, Robert Clausecker wrote:

> Hi folks!
> I try to use this awesome compiler and have several questions.
> 1. I have this program (see atachement):
>  Now, the first solution is faster with both ghc and jhc, but with jhc
> it runs in something like O(n) instead of the second, which runs in
> O(1). Why?

I don't understand what you want to do, certainly because I have not heard of 
Zeckendorf before. However the use of (!!) is discouraged, since it has to scan 
the list from the beginning. Try to avoid it by clever uses of 'zip' or 

The use of 'read' for parsing command line arguments is not correct, since 
'read' expects that the argument string actually represent a value of the 
target type. It aborts your program with an error if the command line argument 
is not a number. You may use
   case reads countStr of
      [(count, "")] -> proceedWith count
      _ -> IO.hPutStrLn ("no or ambigous parse of " ++ countStr) >>
           exitFailure nr

> 2. Are there any special CPP-flags to find out, whether my program is
> compiled with jhc, if CPP is enabled?

I suggest to stay away from CPP. You can move compiler dependent code to 
separate modules and access them with Cabal flags:

Hs-Source-Dirs: src
If impl(jhc)
   Hs-Source-Dirs: src-jhc
   Hs-Source-Dirs: src-gen

More information about the jhc mailing list