-
Notifications
You must be signed in to change notification settings - Fork 379
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 information is lost/changed when inlining a function (and it's not clear why) #3271
Comments
This one also works: decideIsEmptyString' : (s : String) -> Dec (IsEmpty (the (List Char) (unpack s)))
decideIsEmptyString' s with (unpack s)
_ | [] = Yes Empty
_ | (x :: xs) = No uninhabited The issue feels subtle to me, but I think it boils down to Idris doesn't know to replace all of the
More detailsWhen you write a The
I don't know if it's intentional that Also I don't know a good way to get a look at the types of those synthesized functions from the REPL, so I ran with |
@dunhamsteve thanks for your comment! I didn't know that you could run the repl with I find it interesting that the code typechecks by using decideIsEmptyString' : (s : String) -> Dec (IsEmpty (unpack s))
decideIsEmptyString' s with (unpack s)
_ | [] = Yes Empty
_ | (x :: xs) = No uninhabited It'd be nice to have some documentation to better understand what's the expected behavior of |
Yeah, it would be nice to have a discussion of I don't know if this is a desired change, but just for fun I tried teaching diff --git a/src/TTImp/Elab/Case.idr b/src/TTImp/Elab/Case.idr
index 949df8274..290aa70f2 100644
--- a/src/TTImp/Elab/Case.idr
+++ b/src/TTImp/Elab/Case.idr
@@ -212,8 +212,13 @@ caseBlock {vars} rigc elabinfo fc nest env opts scr scrtm scrty caseRig alts exp
fullImps caseretty_in (TType fc u)
let casefnty
= abstractFullEnvType fc (allow splitOn (explicitPi env))
- (maybe (Bind fc scrn (Pi fc caseRig Explicit scrty)
- (weaken caseretty))
+ -- replace scrutinee with scrn in return type
+ (maybe !(do let binder = (Pi fc caseRig Explicit scrty)
+ let env' = binder :: env
+ nfscr <- (nf defs env' (weaken scrtm))
+ nfcaseretty <- (nf defs env' (weaken caseretty))
+ caseretty' <- Normalise.replace defs env' nfscr (Local fc Nothing _ First) nfcaseretty
+ pure $ Bind fc scrn binder caseretty')
(const caseretty) splitOn)
-- If we can normalise the type without the result being excessively
-- big do it. It's the depth of stuck applications - 10 is already |
Note that this leads to a lot of normalisation (and may be missing some occurrences in the context thus leading to ill-typed auxiliary definitions). |
Thanks for taking a look. I suspected there were issues with this change, and I was curious what they were. It looks like
I think this paragraph would be a useful addition to the html docs and will PR that (along with documentation for multi-with). |
Note: I'm not sure whether this is a bug or I don't fully understand how some language feature is supposed to work (I'm currently learning Idris). If you find it's the latter, I'd greatly appreciate it if you could direct me to resources that can fill the gaps in my understanding 🙏
Steps to Reproduce
In this example, which —correctly— typechecks:
replace the application of
decideIsEmpty
by its definition (i.e. inline thedecideIsEmpty
function indecideIsEmptyString
).You're left with:
Note that the type of
unpack s
isList Char
, and the expected type for the expression is stillDec (IsEmpty (unpack s))
.Expected Behavior
The resulting code is equivalent to the original program, so it should typecheck.
Observed Behavior
Both
Yes Empty
andNo uninhabited
stop being valid, and the program no longer typechecks. The errors are:Empty
:uninhabited
:Where
<<(unpack s)-implementation>>
is:Gist with complete program
...including the original
decideIsEmptyString
function and the results of inliningdecideIsEmpty
:https://gist.github.com/JavierGelatti/3025938e81471b625c8276c49ab3614d
The text was updated successfully, but these errors were encountered: