Accessing a Specific Element in a Tuple

后端 未结 7 2072
南笙
南笙 2020-12-11 00:17

Haskell-newbie reporting in. Question is as follows: In Haskell, we have fst and snd that return the first and the second elements of a 2-tuple. Wh

相关标签:
7条回答
  • 2020-12-11 01:03

    N-tuples are not a data structure for indexing via an Int key, instead, you should look at one indexed-biased data structures, such as arrays or finger-trees.

    Now, one could imagine writing a typeclass for a family of tuple types providing an index operation, however, we already have arrays for that, and there's a lot of boilerplate necessary to make tuples of any type seamlessly provide this operation. The power gained isn't worth the effort.

    0 讨论(0)
提交回复
热议问题