Tuples - Difference between Tuple3 and T3

I’m playing around with some graph data structures in Purescript using Tuples. The following does not compile, even though as I reason through all the types, it ought to by my reckoning. The checker does not seem to recognise s as a List of Tuple b Node. I realise in Purescript typically records are recommended for this sort of thing, but I guess I am just curious what is going on. Or have I made some oversight that I can’t see?

You can paste these lines directly into Try.


type  Node   = Int
type Context' a b = Tuple3 (Adj b) a (Adj b)
type Adj b        = List (Tuple b Node)

addSucc :: forall a b. Node -> b -> Context' a b -> Context' a b
addSucc v l (p /\  l' /\  s) = (p /\ l' /\ ((l /\ v): s))

Error returned

Could not match type

    Tuple (List (Tuple b0 Int))

  with type

    List


while trying to match type t1
  with type List (Tuple b0 Int)
while checking that expression s
  has type List (Tuple b0 Int)
in value declaration addSucc

where b0 is a rigid type variable
        bound at (line 0, column 0 - line 0, column 0)
      t1 is an unknown type

You want T3. Tuple3 has a terminal Unit to work with the extensible combinators.
https://pursuit.purescript.org/packages/purescript-tuples/4.1.0/docs/Data.Tuple.Nested#t:Tuple3
https://pursuit.purescript.org/packages/purescript-tuples/4.1.0/docs/Data.Tuple.Nested#t:T3

2 Likes

Thanks, swapping the Tuple3, Tuple4 out to T3, T4 etc. worked a treat. With the following qualification. I did need a little convenience function to do, for example, over4 on a T4 as follows. Posted below in case anyone ever needs to do the same.

-- | Given a 4-tuple, modifies the fourth value.
over4' :: forall a b c d r. (d -> r) -> T4 a b c d -> T4 a b c r
over4' o (a /\ b /\ c /\ d) = a /\ b /\ c /\ o d