About `NamedTuple` with `Selectable`

At first glance NamedTuple with Selectable combination seems fine.
But after some closer consideration. NamedTuples just break the structural typeing nature of Selectable.



class Record extends Selectable {
   def selectDynamic(x: String) = 1
}

type R1 = Record { def f1: Int; def f2: Int }
type R2 = Record { def f2: Int; def f1: Int }
type R3 = Record { def f1: Int }
type R11 = Record { type Fields = (f1: Int, f2: Int) }
type R12 = Record { type Fields = (f2: Int, f1: Int) }

summon[R1 =:= R2] // Yes
summon[R1 <:< R3] // Yes
summon[R1 =:= R11] // No
summon[R11 =:= R12] // No

Is this intentional design or an implementation limitation?

1 Like

This is expected because there is no magic to make different types equal - (e.g. no conversion between type Fields and val refinements)

R11 and R12 is also expected because again no magic.

If you use the Fields encoding, its because you trade that unordered flexibility for a more deterministic implementation