12

Suppose you want to have something like variadic templates (the ability to define n type parameters for a generic class) in Scala.

For example you do not want to define Tuple2[+T1, +T2] and Tuple3[+T1, +T2, +T3] but Tuple[T*].

Are there other options than HLists that would support Tuple, Product and Function?

4
  • 2
    I assume you could roll your own version of HList, but why? Can you point to how your envisioned option would be different from an HList? Apr 7, 2010 at 15:52
  • The type definition on the user side is a bit complicated for my taste. An ideal solution would allow a more natural type definition Tuple[T1,T2,T3] like the TupleX already do in the Scala libs. Additionally, it should support other types like Function and Product. Apr 8, 2010 at 5:22
  • But Scala already offers, and HList uses, some syntactic sugar to reduce that complexity. For instance, see this type definition from the HList link: val list : Int :: String :: Boolean :: HNil = .... Apr 8, 2010 at 11:54
  • 1
    @Daniel This was actually the complexity I was refering to. :-) It is definitely better than HList[Int, HList[String, HList[Boolean, HNil]]] but Tuple3[Int, String, Boolean] is better from a user's perspective (ignoring the 3 in the name). Apr 8, 2010 at 12:52

1 Answer 1

6

At the moment there's no syntactical construct in Scala which allows what you're suggesting. That's also the reason why there are 22 Tuple classes (Tuple2, Tuple3, ..., Tuple22) and also different Function classes (Function0, ...).

1
  • 7
    The question implies that there is not a language construct. Apr 8, 2010 at 5:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.