简体   繁体   English

如何在函数中将元组列表作为参数传递?

[英]How do I pass a list of tuples as an argument in a function?

I want to write a function that takes as an argument a list of three tuples. 我想编写一个函数,该函数将三个元组的列表作为参数。

What I have isn't passing the eval, as I assume that it's reading it as tuple of two ints plus an int list: 我没有通过评估,因为我假设它正在将其读取为两个int加上一个int列表的元组:

fun check_list(tuples : int*int*int list) = so forth and so forth

What is the proper syntax for typing a list of tuples? 键入元组列表的正确语法是什么?

The problem is in your syntax. 问题出在您的语法中。

This int*int*int list is equivalent to int * int * (int list) int*int*int list等效于int * int * (int list)

But what you meant is (int * int * int) list . 但是你的意思是(int * int * int) list The use of parentheses should make it clearer. 使用括号应使其更清楚。

if you want a tuple of three ints then you would pass to a function like so: 如果您想要三个整数的元组,那么您将传递给这样的函数:

fun check_list(a:int,b:int,c:int)=[(a,b,c)];

check_list(1,2,3);

plug it in and try it. 插入并尝试。 I will return [(1,2,3)]. 我将返回[(1,2,3)]。 If I'm understanding your question correctly. 如果我正确理解您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM