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

后端 未结 7 698
隐瞒了意图╮
隐瞒了意图╮ 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:17

    I don't think it's possible to do this in Haskell, for a list of arbitrary length not known at compile time. Template Haskell can't do it because it operates only at compile time. I ran into a case where I needed to do precisely this, and I had to work around it. A database library expects different-length tuples for query arguments, but I have an arbitrary-length list. So I have to skirt around the library interface. It would be nice if it could take a list.

    Basically the issue is that different-length tuples are different types. But the Haskell compiler has to know at compile type what types might exist at runtime. Converting an arbitrary-length list into a tuple at run time could create some type it didn't know about at compile time.

提交回复
热议问题