I'm out of bandwidth at the moment, but let me just remark that this is swampy territory. It's easy to mess up.
A particular challenge is polymorphism:
map :: forall a b. (a->b) -> [a] -> [b]
map f (x:xs) = (f x) : (map f xs)
In the compiled code for map, is a thunk built for (f x), or is it evaluated eagerly. Well, if you can instantiate the 'b' with !Int, say, then it should be evaluated eagerly. But if you instantiate with Int, then build a thunk. So, we really need two compiled versions of 'map'. Or perhaps four if we take 'b' into account. In general an exponential number.
That's one reason that GHC doesn't let you instantiate a polymorphic type variable with an unlifted type, even if it is boxed.
Another big issue is that *any* mixture of subtyping and (Haskell-style) parametric polymorphism gets very complicated very fast. Especially when you add higher kinds. (Then you need variance annotations, and before long you want variance polymorphism.) I'm extremely dubious about adding subtyping to Haskell. That's one reason Scala is so complicated.
But re-imagining GHC is good too. Swampy territory it may be, but it's also important, and there really *ought* to be a more seamless of combining strictness and laziness.
| -----Original Message-----
| From: Dan Doel [mailto:dan.doel@gmail.com]
| Sent: 27 October 2015 23:42
| To: Richard Eisenberg
| Cc: Simon Peyton Jones; ghc-devs
| Subject: Re: Unlifted data types
|
| Hello,
|
| I've added a section with my notes on the minimal semantics required to
| address what Haskell lacks with respect to strict types.
|
| Ed Kmett pointed me to some stuff that I think may fix all the problems with
| the !T sort of solution. It builds on the new constraint being considered
| for handling impredicativity. The quick sketch goes like this. Given the
| declaration:
|
| data Nat = Z | S !Nat
|
| then:
|
| Nat :: *
| !Nat :: Unlifted
| S :: Nat -> Nat
|
| But we also have:
|
| !Nat <~ Nat
|
| and the witness of this is just an identity function, because all values of
| type !Nat are legitimate values of type Nat. Then we can
| have:
|
| case n of
| S m -> ...
| Z -> ...
|
| where m has type !Nat, but we can still call `S m` and the like, because
| !Nat <~ Nat. If we do use `S m`, the S call will do some unnecessary
| evaluation of m, but this can (hopefully) be fixed with an optimization
| based on knowing that m has type !Nat, which we are weakening to Nat.
|
| Thoughts?
|
| -- Dan
|
|
| On Thu, Oct 8, 2015 at 8:36 AM, Richard Eisenberg <eir@cis.upenn.edu> wrote:
| >
| > On Oct 8, 2015, at 6:02 AM, Simon Peyton Jones <simonpj@microsoft.com>
| wrote:
| >
| >> What's the wiki page?
| >
| > https://ghc.haskell.org/trac/ghc/wiki/UnliftedDataTypes
_______________________________________________
ghc-devs mailing list
ghc-devs@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs