-
Notifications
You must be signed in to change notification settings - Fork 641
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 mismatch due to lack of reduction of type defined in the same mutual
block as target function.
#4229
Comments
@JadenGeller Thanks for reporting the issue. |
mutual
block as target function.
Is it expected that the error does not resolve when I move functions that needn't be in data NatTag = Z | S
mutual
NatPayload : NatTag -> List Type
NatPayload Z = []
NatPayload S = [Nat]
Nat : Type
Nat = AlgebraicData NatTag NatPayload
MkNat : (tag : NatTag) -> NatPayload tag *-> Nat
MkNat = MkAlgebraicData
elimNat : ((tag : NatTag) -> NatPayload tag *-> a) -> Nat -> a
elimNat = elimAlgebraicData There's now a type error even earlier, in When checking right hand side of MkNat with expected type
(tag : NatTag) -> (NatPayload tag) *-> Nat
Type mismatch between
(tag : NatTag) ->
(Payload tag) *-> AlgebraicData NatTag Payload (Type of MkAlgebraicData)
and
(tag : NatTag) -> function (NatPayload tag) Nat (Expected type)
Specifically:
Type mismatch between
function (Payload v0) (AlgebraicData NatTag Payload)
and
function (NatPayload v0) Nat
Holes: Main.MkNat |
@JadenGeller Yes, because |
Even when the tag is known, it doesn't seem to simply. data NatTag = Z | S
mutual
NatPayload : NatTag -> List Type
NatPayload Z = []
NatPayload S = [Nat]
Nat : Type
Nat = AlgebraicData NatTag NatPayload
zero : Nat
zero = MkAlgebraicData Z {Payload=NatPayload} In the following error, the tag is known to be When checking right hand side of zero with expected type
Nat
Type mismatch between
(NatPayload Z) *-> AlgebraicData NatTag NatPayload (Type of MkAlgebraicData Z)
and
Nat (Expected type)
Specifically:
Type mismatch between
function (NatPayload Z) (AlgebraicData NatTag NatPayload)
and
Nat If I try to simplify |
I also wouldn't expect |
@JadenGeller There are limits of what Idris can do automatically, because higher-order unification is incomplete (so e.g., it would not try unify the non-injective Also, it does not know what |
@JadenGeller I think that the issue is that in your case, you are passing |
@ahmadsalim I had pasted the wrong error. Explicitly passing the implicit parameter first fails in the same exact way it does when I pass it second. When checking right hand side of zero with expected type
Nat
Type mismatch between
(NatPayload Z) *-> AlgebraicData NatTag NatPayload (Type of MkAlgebraicData Z)
and
Nat (Expected type)
Specifically:
Type mismatch between
function (NatPayload Z) (AlgebraicData NatTag NatPayload)
and
Nat These expressions are clearly beta equivalent, no? |
@JadenGeller Try using |
It looks like it is unable to verify totality for |
@JadenGeller You need a way to show that the recursion decreases in size, how would you ensure this in this case? As far as I can see now, it does not need to. An alternative is to use some type of fuel, that you decrease on each recursion. |
It seems silly to have to prove that though, no? It doesn't decrease in size in the same way that data Nat : Type where
Z : Nat
S : Nat -> Nat doesn't decrease in size when you apply Just like construction of |
I feel like this is related to productivity checking v. decreasing argument checking, right? I know Agda has a way to mark records as coinductive. Would this be useful here? |
All recursive calls do seem to be constructor guarded, so I would expect this to be verified as total by means of productivity. |
If you want to use productivity instead of termination, then the productive bit needs to be wrapped in |
@JadenGeller You are here running into a meta-theoretical problem which Idris can not solve easily. However, when you introduce these recursive type equations explicitly, the theory of Idris has currently no way of determining whether these sets of recursive equations form a valid type. In fact, solving recursive type equations nicely has been a research topic for decades, and you need to use one of these approaches if you want to have your solution be accepted in Idris. |
See also some of the files (like internalMu) here https://github.com/gallais/potpourri/tree/master/agda/poc |
Steps to Reproduce
Compile the following program:
Expected Behavior
The program type checks because
MkNat Z
has typefunction (NatPayload Z) Nat
which is identical toNat
after beta reduction.Observed Behavior
A type error prevent compilation of a correct program.
The text was updated successfully, but these errors were encountered: