Is there a function in SML that adds two tuples of equal lengthes like (3,1,2) and (4,3,1) and returns (7,4,3)?
Thank You
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, there is no such function.
There also is no way to write one yourself without hard-coding the length, i.e. you can write a function that takes two tuples of length 2 or a function that takes two tuples of length 3, but it’s not possible to write one that takes two tuples of arbitrary (but equal) length. SML’s type system simply does not allow you to abstract over a tuple’s length like that.
For a specific length, you can, of course, easily define it yourself: