I have a large enumeration type (example prog below) on which I
have done "deriving Read".  My problem is, the derived read for
lists of these things runs incredibly slowly, so slowly that it
useless for reading anything larger than the smallest quantity
of text.

I also made my own instance of Read for the data type.  This 
improves performance by a factor of about 50, both in time, and
heap allocated.  This is with ghc-2.02 -O on sparc-solaris2.5.

This is not a bug per se, but I feel that it should be considered
as such, because it gives unexpectedly poor behaviour for a task
which one would expect to run reasonably quickly.

J

                 ----------------------------------

module Main where
import List
import Char

data BigEnum
  = C00
  | C01
  | C02
  | C03
  | C04
  | C05
  | C06
  | C07
  | C08
  | C09
  | C10
  | C11
  | C12
  | C13
  | C14
  | C15
  | C16
  | C17
  | C18
  | C19
  | C20
  | C21
  | C22
  | C23
  | C24
  | C25
  | C26
  | C27
  | C28
  | C29
  | C30
  | C31
  | C32
  | C33
  | C34
  | C35
  | C36
  | C37
  | C38
  | C39
    deriving (Eq
              ,Read
             )

{-
instance Read BigEnum where
   readsPrec _ s0
      = case (dropWhile isSpace s0) of
             'C':'0':'0':zz -> [(C00, zz)]
             'C':'0':'1':zz -> [(C01, zz)]
             'C':'0':'2':zz -> [(C02, zz)]
             'C':'0':'3':zz -> [(C03, zz)]
             'C':'0':'4':zz -> [(C04, zz)]
             'C':'0':'5':zz -> [(C05, zz)]
             'C':'0':'6':zz -> [(C06, zz)]
             'C':'0':'7':zz -> [(C07, zz)]
             'C':'0':'8':zz -> [(C08, zz)]
             'C':'0':'9':zz -> [(C09, zz)]
             'C':'1':'0':zz -> [(C10, zz)]
             'C':'1':'1':zz -> [(C11, zz)]
             'C':'1':'2':zz -> [(C12, zz)]
             'C':'1':'3':zz -> [(C13, zz)]
             'C':'1':'4':zz -> [(C14, zz)]
             'C':'1':'5':zz -> [(C15, zz)]
             'C':'1':'6':zz -> [(C16, zz)]
             'C':'1':'7':zz -> [(C17, zz)]
             'C':'1':'8':zz -> [(C18, zz)]
             'C':'1':'9':zz -> [(C19, zz)]
             'C':'2':'0':zz -> [(C20, zz)]
             'C':'2':'1':zz -> [(C21, zz)]
             'C':'2':'2':zz -> [(C22, zz)]
             'C':'2':'3':zz -> [(C23, zz)]
             'C':'2':'4':zz -> [(C24, zz)]
             'C':'2':'5':zz -> [(C25, zz)]
             'C':'2':'6':zz -> [(C26, zz)]
             'C':'2':'7':zz -> [(C27, zz)]
             'C':'2':'8':zz -> [(C28, zz)]
             'C':'2':'9':zz -> [(C29, zz)]
             'C':'3':'0':zz -> [(C30, zz)]
             'C':'3':'1':zz -> [(C31, zz)]
             'C':'3':'2':zz -> [(C32, zz)]
             'C':'3':'3':zz -> [(C33, zz)]
             'C':'3':'4':zz -> [(C34, zz)]
             'C':'3':'5':zz -> [(C35, zz)]
             'C':'3':'6':zz -> [(C36, zz)]
             'C':'3':'7':zz -> [(C37, zz)]
             'C':'3':'8':zz -> [(C38, zz)]
             'C':'3':'9':zz -> [(C39, zz)]
             _              -> []
-}

testStr :: String
testStr 
   = " [ C00, C01, C02, C03, C04, C05, C06, C07, C08, C09, " ++
     "   C10, C11, C12, C13, C14, C15, C16, C17, C18, C19, " ++
     "   C20, C21, C22, C23, C24, C25, C26, C27, C28, C29, " ++
     "   C30, C31, C32, C33, C34, C35, C36, C37, C38, C39 ] "

main = let xx = (read testStr) :: [BigEnum]
       in  
       if   xx == xx
       then putStr "done\n" >> return ()
       else putStr "?!*#@\n" >> return ()

Reply via email to