Afaik, you couldn't UNPACK a list in the past because it's a sum type, and sum types could not be unpacked. That has changed with the latest GHC, so maybe that now works.

I'm pretty certain you can't unpack polymorphic fields, and this is why libraries such as `ad` offer a polymorphic version, and a version specialized to a particular type:

http://hackage.haskell.org/package/ad-4.3.3/docs/Numeric-AD-Mode-Forward.html - polymorphic
http://hackage.haskell.org/package/ad-4.3.3/docs/Numeric-AD-Mode-Forward-Double.html - specialized to Double and significantly faster

Does that help?

On Fri, Jul 28, 2017 at 2:48 PM Tom Ellis <tom-lists-haskell-cafe-2013@jaguarpaw.co.uk> wrote:
What types can be UNPACK'ed?  From my vague understanding of what UNPACK
does, it can only be types whose size is bounded by a known value, so whilst

    data Foo = Foo {-# UNPACK #-} !Float {-# UNPACK #-} !Int

is fine, presumably

    data Foo = Foo {-# UNPACK #-} ![Float]

is not fine.  Or is it?  Technically it could be possible to reserve enough
space in Foo to store either a [] or a (:) Float [Float].  And if that is
possible could we also UNPACK polymorphic fields?

    data Storable a => Foo a = Foo {-# UNPACK #-} a

or

    data Foo a where
        Foo :: Storable a => {-# UNPACK #-} a -> Foo a

if either DatatypeContexts worked or my imaginary GADT UNPACK syntax worked
(I'm not sure if either does).

What are the limits of what we could reasonably get to UNPACK in GHC?

Thanks,

Tom
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.