Question is simple.
How to access a tuple by using Index variable in SML?
val index = 5;
val tuple1 = (1,2,3,4,5,6,7,8,9,10);
val correctValue = #index tuple1 ??
I hope, somebody would be able to help out.
Thanks in advance!
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.
There doesn’t exist a function which takes an integer value and a tuple, and extracts that element from the tuple. There are of course the
#1,#2, … functions, but these do not take an integer argument. That is, the name of the “function” is#5, it is not the function#applied to the value5. As such, you cannot substitute the nameindexinstead of the5.If you don’t know in advance at which place in the tuple the element you want will be at, you’re probably using them in a way they’re not intended to be used.
You might want a list of values, for which the
'a listtype is more natural. You can then access thenth element usingList.nth.