
I like your suggestion!
I think it'd be better to have
TYPE :: TypeShape -> *
data TypeShape = Unboxed | Boxed Levity
data Levity = Lifted | Unlifted
Now the awkward "unboxed/lifted" combination doesn't arise.
Now, 'error' is "TypeShape-polymorphic":
error :: forall (ts :: TypeShape) (a :: TYPE ts). String -> a
What functions (if any) are "Levity-polymorphic". That is, they have identical code regardless of whether their (boxed) type args are lifted or unlifted? Answer: data constructors. As Richard says
Cons :: forall (v1::Levity) (v2::Levity) (a::TYPE (Boxed v1)).
a -> List v1 v2 a -> List v1 v2 a
Why can it be levity-polymorphic? Because data constructors guarantee to construct no intermediate values (which they would be unsure whether or not to evaluate).
Typically, though, functions over lists would not be levity-polymorphic, for reasons previously discussed.
The awkward spot is the runtime system. Currently it goes to some lengths to ensure that it never introduces an indirection for a boxed-but-unlifted type. Simon Marlow would know exactly where. So I suspect that we WOULD need two versions of each (levity-polymorphic) data constructor, alas. And we'd need to know which version to use at every call site, which means the code would need to be levity-monomorphic. So we really would get very little levity polymorphism ineed. I think.
All this fits nicely with Dan Doel's point about making ! a first class type constructor.
Simon
| -----Original Message-----
| From: ghc-devs [mailto:ghc-devs-bounces@haskell.org] On Behalf Of
| Richard Eisenberg
| Sent: 08 September 2015 14:46
| To: ghc-devs
| Subject: Re: Unlifted data types
|
| I have put up an alternate set of proposals on
|
| https://ghc.haskell.org/trac/ghc/wiki/UnliftedDataTypes
|
| These sidestep around `Force` and `suspend` but probably have other
| problems. They make heavy use of levity polymorphism.
|
| Back story: this all was developed in a late-evening Haskell Symposium
| session that took place in the hotel bar. It seems Edward and I walked
| away with quite different understandings of what had taken place. I've
| written up my understanding. Most likely, the Right Idea is a
| combination of this all!
|
| See what you think.
|
| Thanks!
| Richard
|
| On Sep 8, 2015, at 3:52 AM, Simon Peyton Jones