newtypes always turn into no code.   The UNPACK is therefore asking to unpack 
the Integer inside a Day, and that we can't do because Integer has more than 
one data constructor.  Ditto Pico.  So just drop the UNPACKS. Keep the ! 
though, to keep it strict

S

From: [email protected] 
[mailto:[email protected]] On Behalf Of Eugene Kirpichov
Sent: 28 October 2011 10:41
To: Haskell Cafe
Subject: [Haskell-cafe] When does the UNPACK pragma work?

Hi,

I'm trying to speed up Data.Time (the time package) 'cause my program is 
spending a very substantial fraction of time manipulating dates.

I decided to start with strictifying and unpacking the date/time types, as 
there's no point in having them be lazy and I indeed had a lot of allocation in 
date/time arithmetic in my performance profile.

data UTCTime = UTCTime {
    utctDay :: {-# UNPACK #-} !Day,
    utctDayTime :: {-# UNPACK #-} !DiffTime
}

(unpacks and strictness mine)

newtype Day = ModifiedJulianDay {toModifiedJulianDay :: Integer}
newtype DiffTime = MkDiffTime Pico

And Pico is also essentially a newtype for Integer.

So, I'm getting warnings on this definition of UTCTime.
QUESTION: Is it the case that I can only UNPACK primitive fields, and not even 
their newtypes?

Data\Time\Clock\UTC.hs:30:16:
    Warning: Ignoring unusable UNPACK pragma on the
             first argument of `UTCTime'
    In the definition of data constructor `UTCTime'
    In the data type declaration for `UTCTime'

Data\Time\Clock\UTC.hs:30:16:
    Warning: Ignoring unusable UNPACK pragma on the
             second argument of `UTCTime'
    In the definition of data constructor `UTCTime'
    In the data type declaration for `UTCTime'



--
Eugene Kirpichov
Principal Engineer, Mirantis Inc. http://www.mirantis.com/
Editor, http://fprog.ru/
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to