I use the Hugs98 heap profiler, and it sometimes produces lines that the
hp2ps program cannot digest (under MacOS). The lines look like
  Undefined member:  member: nal 27
about which hp2ps says
  line 31: integer must follow identifier
and aborts.

The program I ran was the following:

---- file Shuffle.hs -----------------------------------------------------

module Shuffle (
    shuffle
) where

import Random


getRandomIndex :: [a] -> IO(Int)
getRandomIndex ls = getStdRandom(randomR(0, (length ls) - 1))


remove                :: Int -> [a] -> [a]
remove 0 (x:xs)       = xs
remove n (x:xs) | n>0 = x: remove (n-1) xs
remove _ (_:_)        = error "remove: negative argument"
remove _ []           = error "remove: too large argument"


shuffle :: [a] -> IO [a]
shuffle [] = return []
shuffle ls = do i <- getRandomIndex ls
                do l <- shuffle (remove i ls)
                   return ((ls !! i) : l)

---- file Card.hs -----------------------------------------------------

module Card (

) where

import Shuffle


data Suit = Spade | Heart | Diamond | Club
             deriving (Eq, Ord, Enum)

instance Show(Suit) where
    show Spade = "S"
    show Heart = "H"
    show Diamond = "D"
    show Club = "C"


data Rank = Ace | R2 | R3 | R4 | R5 | R6 | R7 | R8 | R9 | R10
            | Jack | Queen | King
                        deriving (Eq, Ord, Enum)

instance Show(Rank) where
    show Ace = "A"
    show R2 = "2"
    show R3 = "3"
    show R4 = "4"
    show R5 = "5"
    show R6 = "6"
    show R7 = "7"
    show R8 = "8"
    show R9 = "9"
    show R10 = "0"
    show Jack = "J"
    show Queen = "Q"
    show King = "K"


data Card = Card(Suit, Rank)
            deriving (Eq, Ord)

instance Show(Card) where
        show (Card(s, r)) = show s ++ show r


ranks = [ toEnum x :: Rank | x <- [0..12] ]
suits = [ toEnum x :: Suit | x <- [0..3] ]
deck = [ Card(s, r) | s <- suits, r <- ranks ]


shuffledDeck = do d <- shuffle deck
                  putStr (show d)


---- Hugs98 interaction -----------------------------------------------------

[Load Card module]

Card> :s -d1000
Card> shuffledDeck

[Produces the file "profile.hp", which is sent to the hp2ps program.]

  Hans Aberg



Reply via email to