7

I am reading Type driven development with Idris, and one of the exercises asks the reader to define a type TupleVect, such that a vector can be represented as:

TupleVect 2 ty = (ty, (ty, ()))

I solved it by defining the following type:

TupleVect : Nat -> Type -> Type
TupleVect Z ty = ()
TupleVect (S k) ty = (ty, TupleVect k ty)

The following test typechecks:

test : TupleVect 4 Nat
test = (1,2,3,4,())

My question is, why is (1,2,3,4,()) == (1,(2,(3,(4,()))))? I would have thought that the right hand side is a 2-tuple, consisting of an Int and another tuple.

AJF
  • 11,767
  • 2
  • 37
  • 64
larlon
  • 557
  • 1
  • 6
  • 17

1 Answers1

8

Checking the documentation at http://docs.idris-lang.org/en/latest/tutorial/typesfuns.html#tuples, you can see that tuples are represented as nested pairs.

Hence (x, y, z) == (x, (y, z)) for every x, y, z

marcosh
  • 8,780
  • 5
  • 44
  • 74
  • Thanks, @marcosh :-) – larlon Oct 19 '17 at 09:00
  • you're welcome, I'm learning Idris, too. And answering questions is a nice way to learn – marcosh Oct 19 '17 at 09:01
  • 1
    Why, though? In other languages like Haskell, (1, 2, 3) is not equal to (1, (2, 3)) and produces a type error. I guess it's not likely to cause problems, but it seems strange that Idris is permissive in this regard. – Desty Oct 20 '18 at 12:44