How do I convert a list to a tuple in Haskell?

后端 未结 7 714
隐瞒了意图╮
隐瞒了意图╮ 2020-12-01 07:55

How can I best convert a list to a tuple in Haskell:

[1,2,3,4,5,6] -> (1,2,3,4,5,6)
7条回答
  •  悲&欢浪女
    2020-12-01 08:24

    Tuples and lists are very different things. About the best you can do is to manually write a conversion function:

    toTuple :: [a] -> (a,a,a,a,a,a)
    toTuple [a,b,c,d,e,f] = (a,b,c,d,e,f)
    

    Notice how different the types are: the single variable of the list expands to six variables for the tuple. So you'll need one function for each size of tuple.

提交回复
热议问题