Search code examples
haskelltuples

How to get nth element from a 10-tuple in Haskell?


I have to get nth element in a Haskell tuple. And the tuples are like this : (3,5,"String1","String2","String3","String4","String5","String6","String7","String8","String9","String10"). Can you give me an idea so that I can solve this problem? Thanks.


Solution

  • As you may or may not know fst and snd only work for 2-element tuples ie

    fst' (a,b) = a
    

    You have to write you own as far as I know

    get5th (_,_,_,_,a,_,_,_,_,_) = a
    

    As you can see you may want to define your own type.