[Haskell-cafe] When does the UNPACK pragma work?

Simon Peyton-Jones simonpj at microsoft.com
Fri Oct 28 12:20:52 CEST 2011


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: haskell-cafe-bounces at haskell.org [mailto:haskell-cafe-bounces at haskell.org] 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/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20111028/05602425/attachment.htm>


More information about the Haskell-Cafe mailing list