
- Currently, the internals of GHC assign types like "0" the kind GHC.TypeLits.Nat, so Nat and Symbol *must* remain in the GHC.TypeLits module. Unfortunately, the plumbing around GHC.TypeLits.Unsafe want Nat and Symbol to be defined in GHC.TypeLits.Internals. So, I created a TypeLits.hs-boot file to fix the problem. This is highly unsatisfactory, and if something like what I've done here sticks around, we should change the internals of GHC to use GHC.TypeLits.Internals.Nat, getting rid of the import cycle.
Let's NOT have an hs-boot file here. Instead, change PrelNames to tell GHC where Nat and Symbol are defined. It's ok for them to be in Internals.
I'm also unconvinced about the distinction between "Internals" and "Unsafe". To me the former connotes the latter. Import Internals if you know what you are doing; eg that might let you break important invariants. Import a kosher module like TypeLits if you want the Joe Programmer interface.
Simon
From: ghc-devs-bounces@haskell.org [mailto:ghc-devs-bounces@haskell.org] On Behalf Of Richard Eisenberg
Sent: 12 February 2013 02:41
To: Iavor Diatchki
Cc: José Pedro Magalhães; ghc-devs
Subject: Re: RFC: Singleton equality witnesses
I've just pushed a commit to the type-reasoning branch with a strawman proposal of a reorganization of these definitions. Specifically, this commit breaks TypeLits into the following five files:
- GHC.TypeEq, which contains the definitions for (:~:), Void, Refuted, etc.
- GHC.Singletons, which contains the definitions about singletons in general, such as SingI and SingEquality
- GHC.TypeLits.Unsafe, which contains just unsafeSingNat and unsafeSingSymbol
- GHC.TypeLits.Internals, which is necessary to get GHC.TypeLits.Unsafe to have access to the right internals;
this module is not exported from the 'base' package
and
- GHC.TypeLits, which contains the definitions specific to type-level literals.
Some thoughts on this design:
- First off, why is TypeEq part of GHC?? Because we wish to write eqSingNat and eqSingSym in GHC.TypeLits, and that module rightly deserves to be part of GHC. I'm quite uncomfortable with this decision, and I even created a new git repo at github.com/goldfirere/type-reasoninghttp://github.com/goldfirere/type-reasoning to hold the definitions that eventually ended up in GHC.TypeEq. (The repo has nothing in it, now.) Perhaps the best resolution is to move eqSingNat and eqSingSym out of GHC.TypeLits and into an external package, but that seems silly in a different direction. (It is fully technically feasible, as those functions don't depend on any internals.) I would love some feedback here.
- Why is Singletons broken off? No strong reason here, but it seemed that the singletons-oriented definitions weren't solely related to type-level literals, so it seemed more natural this way.
- Making the Unsafe module was a little more principled, because those functions really are unsafe! They are quite useful, though, and should be available somewhere.
- Currently, the internals of GHC assign types like "0" the kind GHC.TypeLits.Nat, so Nat and Symbol *must* remain in the GHC.TypeLits module. Unfortunately, the plumbing around GHC.TypeLits.Unsafe want Nat and Symbol to be defined in GHC.TypeLits.Internals. So, I created a TypeLits.hs-boot file to fix the problem. This is highly unsatisfactory, and if something like what I've done here sticks around, we should change the internals of GHC to use GHC.TypeLits.Internals.Nat, getting rid of the import cycle.
- I've put in the decideSing function as discussed further up in this thread. Its implementation for Nat and Symbol must use unsafeCoerce, but that shouldn't be a surprise.
Unfortunately, the code doesn't compile now. This is because it needs SingI instances for, say, Sing 0. For a reason I have not explored, these instances are not available here, though they seem to be for code written outside of GHC. Iavor, any thoughts on this?
Please tear any of these ideas (or my whole commit) to shreds! It really is meant to be a strawman proposal, but committing these changes seemed the best way of communicating on possible set of design decisions.
Richard
PS: I'm pasting much of this email to the wiki page for posterity.
On Feb 7, 2013, at 10:45 AM, Iavor Diatchki
Hey Gabor,
And why should it be part of base? Don't get me wrong, I'm not saying this is not important/useful. I'm just wondering about the reason to have it in base. Is it tied to TypeLits?
Cheers, Pedro
On Thu, Feb 7, 2013 at 2:21 PM, Gabor Greif
mailto:ggreif@gmail.com> wrote: Oi José,
this is a library-only issue, the branch is in libraries/base, thus somewhat tied to the 7.8 release.
Cheers,
Gabor
On 2/7/13, José Pedro Magalhães
mailto:jpm@cs.uu.nl> wrote: On Wed, Feb 6, 2013 at 7:17 PM, Gabor Greif
mailto:ggreif@gmail.com> wrote: On 2/6/13, Richard Eisenberg
mailto:eir@cis.upenn.edu> wrote: The only thing that stops me from saying "push" is that I think there is a better organization for all of this. The ideas we're discussing here (things like the Void type) don't seem to belong in TypeLits -- it has nothing to do with literals. Time for a GHC.TypeReasoning module? Does someone have a better name?
Sounds okay. We can wiggle around on the new branch 'till we feel comfortable, but I'd like to land this on master before the v7.8 train leaves the station (i.e. the release branch is created).
Can you perhaps summarise exactly what needs to be added to GHC for this to work? It's not immediately clear to me why this is not just a library issue.
Thanks, Pedro
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.orgmailto:ghc-devs@haskell.org http://www.haskell.org/mailman/listinfo/ghc-devs _______________________________________________ ghc-devs mailing list ghc-devs@haskell.orgmailto:ghc-devs@haskell.org http://www.haskell.org/mailman/listinfo/ghc-devs