所以我试图创建这个函数 AgregarMon,它基本上向“Polinomio”添加了一个“Monomio”,Monomio 最终会成为 Polinomio 中的一个元素,它是一个列表。你会更好地理解一点点
type Monomio = (Int, Int)
type Polinomio = [Monomio]
agregarMon :: Monomio -> Polinomio -> Polinomio
agregarMon = \m p -> case m of{ (0,0) -> p;
x -> case p of{[] -> [x];
y:ys -> case (snd x == snd y) of { true -> case ((fst x + fst y)==0) of { true -> ys;
false -> (fst x + fst y , snd x):ys;}
false -> case snd x < snd y of{true -> y: agregarMon x ys;
false -> x:y:ys;}}}}
我一直在看我的代码一个小时,但我找不到问题。错误说:
Polinomios.hs:45:140: error:
Unexpected case expression in function application:
case ((fst x + fst y) == 0) of
true -> ys
false -> (fst x + fst y, snd x) : ys
You could write it with parentheses
Or perhaps you meant to enable BlockArguments?
|
45 | y:ys -> case (snd x == snd y) of { true -> case ((fst x + fst y)==0) of { true -> ys; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
第 45 行是上面代码的第四行。对不起,如果我缺少信息,请让我现在。以防万一,有人不知道,fst 和 snd 在 Prelude 上。fst 从“Monomio”中获取第一个元素,然后获取第二个元素。fst = (a,b)->a snd (a,b) -> b