SnocList not working with Refl
The follow code throws an exceptions with the Type Checker.
import Data.List.Views
takeLast' : (n : Nat) -> (xs : List a) -> List a
takeLast' n xs = reverse $ take n $ reverse xs
takeLast : (n : Nat) -> List a -> List a
takeLast n xs with (snocList xs)
takeLast Z [] | Empty = []
takeLast Z (ys ++ [x]) | (Snoc rec) = []
takeLast (S k) [] | Empty = []
takeLast (S k) (ys ++ [x]) | (Snoc rec) = takeLast k ys ++ [x] | rec
takeLastsAreEquivalent : takeLast' 2 [1, 2, 3] = takeLast 2 [1, 2, 3]
takeLastsAreEquivalent = Refl
Steps to Reproduce
When the file is loaded in the REPL.
Expected Behavior
It should type check.
Observed Behavior
The following error is produced.
Idris> :l /Issue.idr
Type checking /Issue.idr
/Issue.idr:14:24:
When checking right hand side of takeLastsAreEquivalent with expected type
takeLast' 2 [1, 2, 3] = takeLast 2 [1, 2, 3]
Type mismatch between
with block in Main.takeLast Integer 2 [1, 2, 3] (snocList [1, 2, 3]) =
with block in Main.takeLast Integer 2 [1, 2, 3] (snocList [1, 2, 3]) (Type of Refl)
and
[2, 3] = with block in Main.takeLast Integer 2 [1, 2, 3] (snocList [1, 2, 3]) (Expected type)
Specifically:
Type mismatch between
with block in Main.takeLast Integer 2 [1, 2, 3] (snocList [1, 2, 3])
and
[2, 3]
Holes: Main.takeLastsAreEquivalent
See also the attached file (renamed to Issue.txt from Issue.idr). Issue.txt
My guess this is due to snocList/snocListHelp in Data.List.Views not declared as public export so they don't reduce.
@clayrat should snocList be public export? Right now it is just export. I am fairly new to Idris and have not really done anything beyond simple example code.
Yes, I've previously changed some covering functions in Data.List.Views to public export but apparently overlooked these.
Thanks for reporting the issue. It is as @clayrat diagnozed because export functions do not reduce in types of other modules.
@ahmadsalim Could you please elaborate some more on this 'expected behavior' tag? Is the user supposed not to be able to prove takeLast' and takeLast are extensionally equal? Would it break anything if those functions were made public export? EDIT: "those functions" means snocList/snocListHelp.
@anton-trunov It is expected behaviour because export means that only the type signature is exported and not the actual definitions 😄
It's not a language issue, but I guess it is a kind of a library design issue, no?
@ahmadsalim Let me rephrase it this way. Is there a fundamental difference between this issue and #4134?
Well that one was also "expected behaviour" so I guess it's consistent :)
People are welcome to change it to public export.
I am not sure what the library designer had in mind 😄 , so I don't know if it is an obvious library design issue.
May be the error message could at least be improved so that the users sees a hint about this export / public export issue?
@justjoheinz This is already captured by e.g. #3822.