3 ms·
It depends on the language. For instance in Scala you can simulate collections of fixed size as in https://github.com/milessabin/shapeless/blob/master/core/src/
by pathsjs 11y ago
It depends on the language. For instance in Scala you can simulate collections of fixed size as in https://github.com/milessabin/shapeless/blob/master/core/src/main/scala/shapeless/sized.scala https://github.com/milessabin/shapeless/blob/master/core/src...
Then, at runtime, you can cast an unsized list to a sized list giving - say - a function List[A] => Option[Sized[List[A], N5]] that will fail if the list is not of size 5. From then on you can go on letting the compiler keep track of lengths.
Of course, this does not work at all if you have no clue what size your input will have
- clhodapp 11y agoI believe that you don't need to know what size your input will have. Rather, you need to know what size the thing you will be calling will need, right?