我对Haskell很新,可能是一个愚蠢的问题.我想要的是将我的函数作为参数赋予任何运算符.例如:
myFunc :: a -> Int -> Int -> Boolean
myFunc operator a b = a operator b
*Project> myFunc (>) 5 2
True
*Project> myFunc (<=) 5 2
False
Run Code Online (Sandbox Code Playgroud)
请告诉我如何做到这一点!
我有很多具有名称a1,a2,a3,...的对象我需要将它们放入List中,因此使用它们更简单,我会以某种方式使用循环吗?
我的尝试是:
List<SomeObject> list = new LinkedList<SomeObject>();
for (int i=0; i<1000; i++){
String varName = "a"+i;
list.add((SomeObject) varName);
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下有人有建议吗?在循环内创建变量不是解决方案,因为它们是.fxml文档的一部分.或者给我一个如何用循环创建它的建议,因为它在.fxml中创建行并行添加循环新对象.
为了更容易理解.fxml文件看起来像
<SomeObject fx:id="a1" *other props* />
<SomeObject fx:id="a2" *other props* />
<SomeObject fx:id="a3" *other props* />
<SomeObject fx:id="a4" *other props* />
Run Code Online (Sandbox Code Playgroud)
非常感谢您的建议!