0

The following snippet compiles fine in Idris 2,


divMod2 : Nat -> (Nat, Bool)
divMod2 Z = (Z, False)
divMod2 (S Z) = (Z, True)
divMod2 (S (S n)) = case divMod2 n of (k, r) => (S k, r)

lm : {q:_} -> divMod2 (q+q) = (q, False)
lm {q=0} = Refl
lm {q=S q} = rewrite sym $ plusSuccRightSucc q q in
             rewrite lm {q} in Refl

but it caused Idris 1.3.4 to fail:

   |
14 |              rewrite lm {q} in Refl
   |                      ~~~~~~
When checking right hand side of lm with expected type
        divMod2 (S q + S q) = (S q, False)

When checking an application of function rewrite__impl:
        Type mismatch between
                (q1, False) = (q1, False) (Type of Refl)
        and
                case divMod2 (plus q q) of   (k, r) => (S k, r) = (q1, False) (Expected type)

        Specifically:
                Type mismatch between
                        (q1, False)
                and
                        case divMod2 (plus q q) of
                          (k, r) => (S k, r)

I know Idris 1 has become obsolete, but am still curious about the underlying reason behind this observation. Could someone help to explain this?

I've done a bit more dig here and found surprisingly that Idris1 failed to compile the following even simpler code snippet, which compiles correctly by Idris2:

f : Nat -> (Nat, Bool)
f Z = (Z, False)
f (S n) = case f n of (k, r) => (S k, r)

h2 : {q:_} -> f (S (q+1)) = case f (q+1) of (k, r) => (S k, r)
h2 = Refl

It spit error message:

   |
19 | h2 = Refl
   |      ~~~~
When checking right hand side of h2 with expected type
        f (S (q + 1)) = case f (q + 1) of   (k, r) => (S k, r)

Type mismatch between
        case f (plus q 1) of   (k, r) => (S k, r) = case f (plus q 1) of   (k, r) => (S k, r) (Type of Refl)
and
        case f (plus q 1) of   (k, r) => (S k, r) = case f (plus q 1) of   (k, r) => (S k, r) (Expected type)

Specifically:
        Type mismatch between
                case f (plus q 1) of
                  (k, r) => (S k, r)
        and
                case f (plus q 1) of
                  (k, r) => (S k, r)

Aren't the two mismatching terms identical? Why couldn't be constructed with Refl?

  • fwiw just today someone posted in the discord an Idris2 example of two identical expressions failing to unify – joel Sep 14 '22 at 22:43

0 Answers0