-
Notifications
You must be signed in to change notification settings - Fork 642
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
Implementation arguments containing injective functions #3727
Comments
@nicolabotta I believe this was previously a bug, which is now fixed. I believe the general idea is that one should not be able to write implementations that work on functions instead of type constructors. |
I am not sure that I understand what you mean, here This late change in Idris breaks tons of legacy code and effectively makes types that are not introduced via What have we gained through this new limitation? |
As far as I understand, the mechanism was only guaranteed to work with type and data constructors, because they guarantee injectivity. I think there were some issues with the old approach, which was fixed prior to the release of 1.0. For more details, I think you need to ask Edwin, since I do not completely understand the implementation search mechanism of Idris myself. |
Thanks Ahmad, for the time being I will go back to 0.99 and try to see if I can make the framework 1.0 compatible. |
Yes, this is correct. I hadn't realised there was code out there which exploited this bug but I'll see if I can think of a way to deal with this kind of implementation. The problem with this kind of implementation constraint is that unification is not fancy enough to deal with it. Maybe the thing to do is revisit unification. |
@nicolabotta I think you can use instead: > implementation Uninhabited (DPair Nat (\ n => LT n Z)) where
> uninhabited (MkDPair n prf) = absurd prf It's a bit more ugly, but should work. |
Hmmm ... it does not seem to work with 1.0-git:981b014:
yields
and
yields
|
@nicolabotta I forgot the paranthesis in my initial comment, but I had corrected it a second later. > implementation Uninhabited (DPair Nat (\ n => LT n Z)) where
> uninhabited (MkDPair n prf) = absurd prf |
@ahmadsalim Thanks, I realized that but also the parenthesized version does not type check with 1.0-git:981b014:
|
@nicolabotta Ah, sorry, I accidentally tested this on 0.99. Yeah, this does seem like an issue. |
@ahmadsalim Thanks Ahmad! I am then going back to 0.99 for the time being. Hope that interfaces will be fixed soon. Best, Nicola |
Would it be possible to come up with an authoritative decision on this issue? The issue is labelled as
does not type check is an error that will hopefully be eradicated. I am open to either decision although 1) would obviously make Sigma types in Idris rather pointless. I understand that in case of 2) it might take a long time to fix the issue. Still, a decision would allow me to make a plan: this issue is the reason why I am still stuck with Idris 0.99. |
@nicolabotta Would it work fine for you if it was possible to use named instances with this kind of pattern? |
So e.g. implementation [uninhabitedlt] Uninhabited (DPair Nat (\ n => LT n Z)) where
uninhabited (MkDPair n prf) = absurd prf would type check. |
@ahmadsalim I do not know! It depends on what are the implications of using named instances. If it was possible to write something like
for suitable definitions of |
@nicolabotta I think you can use |
Because |
Thinking about this, this might still be better than the current situation. |
Can we start with the instance declaration? The first step would be to make
type check. How difficult would this be? |
@nicolabotta I am currently trying to do this in the background, let me see if it compiles/has any issues. |
@ahmadsalim Great, thanks! |
Great, next step is to make the instance declaration usable! The code
fails to type check with
but it type checks fine in Idris 0.99. Any idea how to proceed? Thanks, Nicola |
@nicolabotta There are two ways you could use the named implementation, either: LTB : Nat -> Type
LTB b = DPair Nat (\ n => LT n b)
implementation [gugu] Uninhabited (LTB Z) where
uninhabited (MkDPair n prf) = absurd prf
toFin : {b : Nat} -> LTB b -> Fin b
fromFin : {b : Nat} -> Fin b -> LTB b
using implementation gugu
fromFinToFinLemma : {b : Nat} -> (n : LTB b) -> fromFin (toFin n) = n
fromFinToFinLemma {b = Z} k = absurd k
{- Other code relying on gugu -} or LTB : Nat -> Type
LTB b = DPair Nat (\ n => LT n b)
implementation [gugu] Uninhabited (LTB Z) where
uninhabited (MkDPair n prf) = absurd prf
toFin : {b : Nat} -> LTB b -> Fin b
fromFin : {b : Nat} -> Fin b -> LTB b
fromFinToFinLemma : {b : Nat} -> (n : LTB b) -> fromFin (toFin n) = n
fromFinToFinLemma {b = Z} k = absurd @{gugu} k Note because the implementation has a non-injective parameter, you may be forced to use the explicit passing (second) style sometimes because failing to resolve it. |
@nicolabotta Note I added a test with your previous example code: |
@ahmadsalim Many thanks! |
Sure, you are most welcome 😄 |
The program
type checks fine in 0.99.1-git:PRE. But with 1.0 one gets
which seems like an Idris error given that
LTB Z
is indeed a type.The text was updated successfully, but these errors were encountered: