-
Notifications
You must be signed in to change notification settings - Fork 571
Type-level naturals #3058
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type-level naturals #3058
Conversation
* Solve ConsSymbol
This adds and solves a new 'magic' constraint,
`Type.Data.Symbol.ConsSymbol`, with the following functional
dependencies:
class ConsSymbol (head :: Symbol)
(tail :: Symbol)
(sym :: Symbol) | sym -> head tail, head tail -> sym
* The `head tail -> sym` direction works like `AppendSymbol`, but only
resolves when `head` is a singleton symbol.
* The `sym -> head tail` direction deconstructs the symbol into its
first character and the remaining string.
* Style fixes
* Add proxies * Add failing proxy test cases * Make proxy types of higher precedence * Proxy is no longer reserved * Move "proxy" to reservedTypeNames * s/proxy/@/g
* Add applicative do notation * Test the order of arguments to the result of an applicative do-block * Implement let statements in applicative do-blocks * Correctly handle PositionedDoNotationElement in applicative do-notation * Prefer map over pure when desugaring applicative do-notation * Delete AdoLetNotSupported variant
|
How about putting the classes in |
…cript#3027)" (purescript#3030) This reverts commit 59d1c6a.
* Add instance chain groups * Make OverlappingInstances an error
* Add inlining for runEffFnN/mkEffFnN * Magic-do case to improve EffFn usage From natefaubion purescript#3026 (comment) * Apply magicDo until fixed point * Rearrange magic do optimizations * Stop run(Eff)FnX optimisation firing from local definitions * Add EffFn optimisation test
|
That makes sense, I'll do that. Does that mean that there are plans to move the |
|
I think |
* Add kind Nat
* Solve IsNat
* Solve AddNat
8a32cfc to
7b3ea85
Compare
b535934 to
9ffb15d
Compare
| pattern TypeDataNat :: ModuleName | ||
| pattern TypeDataNat = ModuleName [ProperName "Prim", ProperName "Nat"] | ||
|
|
||
| pattern CompareNat :: Qualified (ProperName 'ClassName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can these move to Prim.Nat as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should rename this patsyn to PrimNat, but as far as I can tell, all the purely typelevel classes are in Prim.Nat now - I didn't move IsNat, because it has a reifyNat function. Wouldn't that be a problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
Wouldn't that be a problem?
Yes, it would, unless we find a better way to encode things. We could always say the integer is the dictionary, but then we wouldn't be able to write the class definition in such a way that people couldn't write bad instances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll also need to add these to primClasses, and also add docstrings for them in the corresponding Docs module, so that they can be linked on Pursuit.
|
@kcsongor Do you think this could be finished before we make a 0.12 release candidate? Skipping powers and roots wouldn't be the end of the world, I think, since we could implement those later. Also, |
|
Oh, definitely. I’m going to update this tomorrow |
|
Another question: At the moment, we don't have polymorphic literals, which means that once we commit to Implementation-wise, this is trivial, and I think it would allow us to cover more ground. |
I feel like ints aren't as useful from a proving-things point of view. What induction principle would you use? |
|
correction:
And negative numbers simply don't satisfy the superclass constraint. |
|
If you forget the |
|
You could always build the induction principle into |
Yes, that's a good point.
foreign import kind Int
foreign import data Pos :: Nat -> Int
foreign import data Neg :: Nat -> Intand I think |
|
Annoyingly you get two zeros with that |
|
Negative and non-negative is another way to go, where |
|
The Grothendieck construction seems to be a nice way though, with an int being a pair of nats, with an equivalence relation such that only the signed difference matters. |
|
@paf31 I've moved the classes to As an additional point, the kind signature of Thanks |
|
Excellent, thanks! I could tell it was going to be a little hairy |
|
This hasn't seen activity in some time. Should this be closed? |
|
I'm going to close this for now due to lack of movement, but I'll be happy to reopen if you manage to find time to pick this up again. For anyone else who might like to pick this up, please feel free to submit a new PR building on top of this too. |
A first attempt at implementing some of the features in #2899
This is incomplete - PR opened for discussion
NatToPeanowould allow to recurse on naturals easily - not sure how important this will be in the presence of instance chains thoughthis allows us to write