0

This compiles:

data ThreeEq : a -> b -> c -> Type where
    Same3 : (x : a)  -> ThreeEq x x x

allSameS : (x, y, z : Nat) -> ThreeEq x y z -> ThreeEq (S x) (S y) (S z)
allSameS k k k (Same3 k) = Same3 (S k)

But with one small change to Same3, it no longer compiles. Can anyone explain why?

data ThreeEq : a -> b -> c -> Type where
    Same3 : x -> ThreeEq x x x

allSameS : (x, y, z : Nat) -> ThreeEq x y z -> ThreeEq (S x) (S y) (S z)
allSameS k k k (Same3 k) = Same3 (S k)

Here's the error message:

- + Errors (1)
 `-- Amy2.idr line 5 col 0:
     When checking left hand side of allSameS:
     When checking an application of Main.allSameS:
             Type mismatch between
                     ThreeEq x x x (Type of Same3 _)
             and
                     ThreeEq k y z (Expected type)

             Specifically:
                     Type mismatch between
                             Type
                     and
                             Nat
mhwombat
  • 8,026
  • 28
  • 53

1 Answers1

1

Here is the difference

data ThreeEq : a -> b -> c -> Type where
    Same3 : (x : a)  -> ThreeEq x x x
             ^   ^
             |   |
             |    Type
             Value

Here, Same3 Z builds a value of type Three Z Z Z.

data ThreeEq : a -> b -> c -> Type where
    Same3 : x -> ThreeEq x x x
            ^
            |
            Type

And now, Same3 Z builds a value of type Three Nat Nat Nat.

Nicolas
  • 24,509
  • 5
  • 60
  • 66