[Haskell-cafe] Some random newbie questions

Greg Buchholz haskell at sleepingsquirrel.org
Thu Jan 6 17:49:46 EST 2005

Benjamin Pierce wrote:
> * What are the relative advantages of Hugs and GHC, beyond the obvious (Hugs
>   is smaller and easier for people not named Simon to modify, while GHC is a
>   real compiler and has the most up-to-date hacks to the type checker)?  Do
>   people generally use one or the other for everything, or are they similar
>   enough to use Hugs at some moments and GHC at others?
> * I wrote a little program for generating Sierpinkski Carpets, and was
>   astonished to find that it runs out of heap under Hugs (with standard
>   settings -- raising the heap size with -h leads to a happier result).

    As one data point, I don't think "SOEGraphics" works with GHC or
recent versions of Hugs (http://www.haskell.org/soe/graphics.htm).  I
also tried a modified version of your Sierpinkski carpet program
(changed to spit out a PostScript file, since I don't have SOEGraphics).
Hugs chokes without increasing the stack, while my copy of GHC 6.2.1 runs
the program below quite fine, even without enabling optimizations.

Greg Buchholz

--Floating point PostScript version of Sierpinkski Carpet

fillSquare x y s = putStr $ x1 ++ y2 ++
                            x1 ++ y1 ++
                            x2 ++ y1 ++
                            x2 ++ y2 ++ " box\n"
    x1 = (show  x)    ++ " "
    x2 = (show (x+s)) ++ " "
    y1 = (show  y)    ++ " "
    y2 = (show (y+s)) ++ " "

carpet x y s =
  if s < 1
  then fillSquare x y s
  else let s' = s / 3
        in do carpet x        y        s'
              carpet (x+s')   y        s'
              carpet (x+s'*2) y        s'
              carpet x        (y+s')   s'
              carpet (x+s'*2) (y+s')   s'
              carpet x        (y+s'*2) s'
              carpet (x+s')   (y+s'*2) s'
              carpet (x+s'*2) (y+s'*2) s'

psPreamble = putStr $ "%!PS-Adobe-2.0\n" ++
                      "/box\n" ++
                      "{ newpath moveto lineto lineto lineto closepath fill}" ++
                      "def\n 0.05 setlinewidth\n"

main = do psPreamble
          carpet 50 250 500
          putStr "showpage\n"

More information about the Haskell-Cafe mailing list