[Haskell-cafe] Re: Write Haskell as fast as C.

Ketil Malde ketil at malde.org
Sat May 17 05:02:50 EDT 2008

Don Stewart <dons at galois.com> writes:

>>> mkAnn :: ByteString -> Annotation
>>> mkAnn = pick . B.words
>>>     where pick (_db:up:rest) = pick' up $ getGo rest
>>>           pick' up' (go:_:ev:_) = Ann (B.copy up') (read $ B.unpack go) (read $ B.unpack ev)
>>>           getGo = dropWhile (not . B.isPrefixOf (pack "GO:"))

>     read $ B.unpack go
> Looks suspicious. You're unpacking to lists.
> ByteString performance rule 1: don't unpack to lists.

I tend to use this idiom a bit when I want to loop over the
characters.  The strings being unpacked is an Int and a short (two or
three letter) identifier.  Doing a 'go' loop would probably be faster,
but a lot more work, and I was hoping the String would be deforested
or fused or otherwise optimized to the bone.

I wonder if the culprit is the last 'read', it reads one from a set of
keywords/identifiers, and since they're upper case, I just made a data
type with a matching set of nullary constructors, and derived "Read"
for it.


> data EvidenceCode = IAC | IUG | IFR | NAC | NR | ... deriving Show

Could it be that this derived read instance is somehow very inefficient?

If I haven't seen further, it is by standing in the footprints of giants

More information about the Haskell-Cafe mailing list