我有以下功能,它应该将给定列表中的所有数字相加到当前位置.例如,subtotal [1, 2, 3, 4] = [1, 3, 6, 10]因为1 = 1,1 + 2 = 3,1 + 2 + 3 = 6并且1 + 2 + 3 + 4 = 10.
这是我的代码:
subtotal :: Num a => [a] -> [a]
subtotal [] = []
subtotal xs = [y | n <- [1..length xs], y <- sum(take n xs)]
Run Code Online (Sandbox Code Playgroud)
问题是我得到这个错误:
cw.hs:3:46: error:
* Couldn't match expected type `[a]' with actual type `a'
`a' is a rigid type variable bound by …Run Code Online (Sandbox Code Playgroud) 我正在尝试了解左联想语法和右联想语法的工作原理,我需要一些帮助。所以我决定举一个例子并要求一些澄清。基本上,我想为两个逻辑操作创建语法:and+ implication。我想让它成为and左关联和implication右关联。这是我到目前为止所得到的。它是否正确?我感觉可能有歧义。(我还记得 的and优先级高于implication)
<exp> := <and>
<and> := <impl> | <and> ^ <impl>
<impl> := <term> | <term> -> <impl>
<term> := (<exp>) | <bool>
<bool> := true | false
Run Code Online (Sandbox Code Playgroud) 我有一个带有以下按钮的GUI.当它被按下时,它应该运行一个新线程(我有一个实现Runnable的类).但是,当我这样做时,GUI会冻结.我做错了什么,如何解决?
//button
addKitchenStaff.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
//create object of a class which implements runnable
KitchenStaff kitchenStaff = new KitchenStaff(allDishes, ingredientsModel, dishesModel,communication.getBap());
//arraylist of all such objects
allKitchenStaff.add(kitchenStaff);
Thread thread = new Thread(kitchenStaff);
thread.run();
}
});
Run Code Online (Sandbox Code Playgroud)