Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Tuple0-22 and Function0-22 instead of a HList

Is there a reason (performance, memory, typesystem) why a Tuple is not a HList and Function is not a mapping form a HList to some value?

like image 403
Manuel Schmidt Avatar asked Jan 24 '13 11:01

Manuel Schmidt


2 Answers

Performance and memory both. Tuples have O(1) access for their elements; as typically constructed, HList is a list, and thus has O(n). Also, tuples require memory for one extra object with n references to other objects, while HList (as a list) requires one object each (plus a next pointer). Since the overhead of an object is about two references, this turns n+2 memory usage into 4n+2. Not so awesome for a core language construct.

like image 193
Rex Kerr Avatar answered Nov 20 '22 13:11

Rex Kerr


An HArray which extends AnyVal will probably have comparable performance and memory requirements as the TupleX classes. The only overhead will be the length of the array and the array index bounds checking.

like image 45
Jesper Nordenberg Avatar answered Nov 20 '22 15:11

Jesper Nordenberg