[Haskell-cafe] What can be UNPACK'ed?
Tom Ellis
tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Sat Jul 29 12:35:45 UTC 2017
Thanks, that's helpful info, but what I'm really after is a definitive
condition under which fields can be UNPACK'ed. The docs are very vague:
https://downloads.haskell.org/~ghc/7.0.2/docs/html/users_guide/pragmas.html
On Fri, Jul 28, 2017 at 03:01:02PM +0000, Oliver Charles wrote:
> 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 at 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?
More information about the Haskell-Cafe
mailing list