hlist

Applying an argument list to curried function using foldLeft in Scala

独自空忆成欢 提交于 2019-11-27 08:19:02
Is it possible to do a foldLeft on a list of arguments, where the initial value supplied to the fold is a fully curried function, the operator is apply , and the list is a list of arguments to be passed to function f ? For example, let's say f is defined as: scala> val f = (i: Int, j: Int, k: Int, l: Int) => i+j+k+l f: (Int, Int, Int, Int) => Int = <function4> Which we can of course use directly: scala> f(1, 2, 3, 4) res1: Int = 10 Or curry and apply the arguments one at a time: scala> f.curried res2: Int => Int => Int => Int => Int = <function1> scala> f.curried.apply(1).apply(2).apply(3)

Are HLists nothing more than a convoluted way of writing tuples?

☆樱花仙子☆ 提交于 2019-11-27 05:48:40
I am really interested in finding out where the differences are, and more generally, to identify canonical use cases where HLists cannot be used (or rather, don't yield any benefits over regular lists). (I am aware that there are 22 (I believe) TupleN in Scala, whereas one only needs a single HList, but that is not the kind of conceptual difference I am interested in.) I've marked a couple of questions in the text below. It might not actually be necessary to answer them, they are more meant to point out things that are unclear to me, and to guide the discussion in certain directions.