0

I'm deconstructing a list into head and tail but later I need a proof that they give me the original list back when combined:

test: Bool -> String
test b = let lst = the (List Nat) ?getListFromOtherFunction in
        case lst of
          Nil => ""
          x :: xs =>
            let eq = the ((x::xs) = lst) ?howToDoIt in ""

I'm using Idris 1.3.1.

simpadjo
  • 3,947
  • 1
  • 13
  • 38

1 Answers1

2

You can do it with dependent pattern matching:

test: List Nat -> String
test lst with (lst) proof prf
  | Nil = ""
  | (x :: xs) = ?something

Here prf will hold your equality.

However, I think it's better to simply match on lst in the LHS, then your proofs will auto-simplify where needed.

  • thank you! I must learn dependent p-m. But it seems that `with` can be used only for top-level function arguments. I modified my question a bit. Is it possible now? – simpadjo Dec 25 '18 at 08:36
  • Yes, that's a somewhat unfortunate limitation. It can be side-stepped by making an auxilliary function for the remainder of your proof and using `with` on the top level in it. – Alexander Gryzlov Feb 22 '19 at 20:42