Nubkadiya
Nubkadiya

Reputation: 3475

Writing a function List to a tuple

how to write a function from list to a tuple

i have taken the string to a tuple. but i need to send it to a tuple.

can someone help me

Upvotes: 2

Views: 299

Answers (1)

kennytm
kennytm

Reputation: 523214

You can't convert an arbitrarily long list to a tuple because tuples of different lengths are considered as distinct types. But you can have:

listToTuple2 :: [a] -> (a, a)
listToTuple3 :: [a] -> (a, a, a)
listToTuple4 :: [a] -> (a, a, a, a)
listToTuple5 :: [a] -> (a, a, a, a, a)

etc.

See also http://www.haskell.org/haskellwiki/Template_Haskell#Convert_the_first_n_elements_of_a_list_to_a_tuple.

Upvotes: 3

Related Questions