Unlifted data types

Edward Z. Yang ezyang at mit.edu
Sat Sep 5 03:38:27 UTC 2015


Excerpts from Dan Doel's message of 2015-09-04 14:48:49 -0700:
> I don't really understand what this example is showing. I don't think
> SPair is a legal
> declaration in any scenario.
> 
> - In current Haskell it's illegal; you can only put ! directly on fields
> - If !a :: Unlifted, then (,) (!a) is a kind error (same with Force a)

This is true. Perhaps it should be possible to define data types which
are levity polymorphic, so SPair can kind as * -> * -> *, Unlifted ->
Unlifted -> *, etc.

> > I don't think it interacts any differently than with unpacked/unboxed
> > products today.
> 
> I meant like:
> 
> If T :: Unlifted, then am I allowed to do:
> 
>     data U = MkU {-# UNPACK #-} T ...
> 
> and what are its semantics? If T is a sum, presumably it's related to
> the unpacked
> sums proposal from a couple days ago. Does stuff from this proposal
> make that proposal
> simpler? Should they reference things in one another?

Ah, this is a good question.  I think you can just directly UNPACK
unlifted types, without a strict bang pattern.  I've added a note to the
proposal.

> Will there be optimizations that turn:
> 
>     data E a b :: Unlifted where
>       L :: a -> E a b
>       R :: b -> E a b
> 
> into |# a , b #| (or whatever the agreed upon syntax is)? Presumably yes.

Yes, it should follow the same rules as
https://ghc.haskell.org/trac/ghc/wiki/UnpackedSumTypes#Unpacking

Edward


More information about the ghc-devs mailing list