-
Notifications
You must be signed in to change notification settings - Fork 58
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
Pretty printing of duplicate names should avoid name clashes #236
Comments
I think this is a bug with the idris name pretty printer.
you'd get the error:
which is idris2 saying: I'm not allowing you to ask me to compare values of pattern variables at runtime, you're going to have to choose an equality function yourself. I think what's happening behind the scenes is that idris2 prints out the string representation of the name for the pattern variable for @edwinb : do you think this could be the bug I've been having with Frex? I'm keen on having it fixed. If you're too busy, I'll take a crack at it. (Though if it's what I think it is, you'll be able to do it in a jiffy.) If my summary above is correct, a fix would be to change the error message into:
|
Yeah, that's what I figured. I actually noticed after posting that the Atom plugin prints the second b as a b1 like I suggested in my post (obviously b' works too), but I guess that's just a left-over from what it does in Idris 1. I'm not sure whether that's specific to the package or how Idris wants to handle these problems. To me, once you introduce pattern matching on types etc. like Idris 2 does, being able to do things like this smoothly seems quite natural (and surely half the point of not blindly erasing them). Obviously you can't pattern match like this on values normally, but that's also because it's hard to think of scenarios where you would - and I think these features need to be rethought when they work on a much wider scope too, ie types. Isn't it possible to at least have an Also, come to think of it, if "names which are in scope in a type are also always in scope in the body of the corresponding definition," is there any feasible scenario in Idris 2 where you would need to introduce a new variable b equal to a in the definition like that? It seems like any working variant of |
I'm not going to defend the design decision 'names which are in scope in a type are also always in scope in the body of the corresponding definition' as I don't agree with it :D. I think that what you are arguing for is that we should be able to write this function:
I don't think we should. I think it might be some kind of philosophy in dependently typed programming: pattern variables (i.e., binding occurences) should be given distinct names (rather than enforce equality). Case splitting should be driven by runtime information in constructors. Equality between names in different places in the pattern must only be deduced by other kind of type-dependency, induced by a concrete constructor. But what do I know, I'm a newbie in this area, so I'll leave the philosophy to the experts. A less philosophical argument --- here's a different program, but related to your program:
This type-checks in Idris1 but not in Idris 2:
so, unless this is a bug in idris2, it seems like we're moving away from nuanced disambiguation using type information for overloading resolution, let alone for actual case-splitting. |
Thank you, that's an interesting insight. I never thought to separate them into distinct namespaces like that. I also think I agree with you that this is not a problem for a pattern match to solve. I still think it'd be useful to leverage that same syntactical equivalence of types, or whatever you call it, (where f : {a, b : Type} -> Either a b -> Either b a
f x with (a == b)
f x | True = x
f (Right x) | False = Left x
f (Left x) | False = Right x I suppose there's no point anyway if this wouldn't lead to the necessary type information for the |
You can write a simulator To be able to decide the equality between type The solution to your problem is to define a universe of the types you are |
Thanks, makes sense. That idea will work for me. Apologies for the confusion! I'll modify this issue to be about the part that's actually (maybe) unintentional. |
Okay, then I will! One reason is that this way is consistent with what is displayed in holes. For example, if you have:
Then you say
You get:
If the names are displayed but not in scope, that's strange. So the point of the decision is, among other things, to make the display consistent with what's in scope. As for the duplicate display, I've been wondering how to do this nicely for ages. One risk, if we're not careful, is we end up displaying a different name than the one which is in scope. I haven't thought about it very deeply though. This issue gives a good chance to think about a nice way to do it (it's probably not one I'll look at urgently, though, sorry.) |
In Agda, the goals' context is simply listing the renamed variables which is So if you ask the type of id : {A : Set} {A : Set} {A : Set} -> A -> A
id = λ x → x then the printer tells you it's {A : Set} {A = A₁ : Set} {A = A₂ : Set} → A₂ → A₂ I think that is a pretty good design. I wonder whether it would make |
Responding to @edwinb : |
Steps to Reproduce
Expected Behavior
Something like:
Observed Behavior
The text was updated successfully, but these errors were encountered: