Idris-dev icon indicating copy to clipboard operation
Idris-dev copied to clipboard

SnocList not working with Refl

Open MikeMKH opened this issue 8 years ago • 12 comments

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

MikeMKH avatar Feb 13 '18 23:02 MikeMKH

My guess this is due to snocList/snocListHelp in Data.List.Views not declared as public export so they don't reduce.

clayrat avatar Feb 13 '18 23:02 clayrat

@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.

MikeMKH avatar Feb 15 '18 12:02 MikeMKH

Yes, I've previously changed some covering functions in Data.List.Views to public export but apparently overlooked these.

clayrat avatar Feb 15 '18 12:02 clayrat

Thanks for reporting the issue. It is as @clayrat diagnozed because export functions do not reduce in types of other modules.

ahmadsalim avatar Feb 15 '18 16:02 ahmadsalim

@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 avatar Feb 15 '18 16:02 anton-trunov

@anton-trunov It is expected behaviour because export means that only the type signature is exported and not the actual definitions 😄

ahmadsalim avatar Feb 15 '18 16:02 ahmadsalim

It's not a language issue, but I guess it is a kind of a library design issue, no?

clayrat avatar Feb 15 '18 16:02 clayrat

@ahmadsalim Let me rephrase it this way. Is there a fundamental difference between this issue and #4134?

anton-trunov avatar Feb 15 '18 16:02 anton-trunov

Well that one was also "expected behaviour" so I guess it's consistent :)

clayrat avatar Feb 15 '18 16:02 clayrat

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.

ahmadsalim avatar Feb 15 '18 16:02 ahmadsalim

May be the error message could at least be improved so that the users sees a hint about this export / public export issue?

justjoheinz avatar Feb 21 '18 14:02 justjoheinz

@justjoheinz This is already captured by e.g. #3822.

ahmadsalim avatar Feb 21 '18 14:02 ahmadsalim