【发布时间】:2018-01-11 11:12:02
【问题描述】:
我正在尝试为我的输入列表创建一个过滤器,以删除最后一个元素不是列表的最后一个列表的元素的列表
我对 Haskell 还很陌生,所以这可能只是一些愚蠢的菜鸟错误
FilterBoi xs = filter (\x -> elem (x) y) xs
Where x = last (x:xs)
y = last xs
返回错误
Occurs check: cannot construct the infinite type:
a ~ t0 a
Expected type: [t0 a]
Actual type: [a]
In the first argument of `last' , namely `xs'
In the expression: last xs
In an equation for `y' : y = last xs
Relevant bindings include
y :: t0 a (bound at filter.hs:3:22)
xs :: [a] (bound at filter.hs:1:11)
FilterBoi :: [a] -> [a] (bound at filter.hs:1:1)
Failed, modules loaded: none.
请注意,我是在手机上输入的,所以问题不在于我输入的方式,而在于我输入的内容
【问题讨论】:
-
A where 是每个 function 子句而不是每个 lambda 表达式。
-
啊,谢谢。关于我应该如何实现我的目标的任何建议?
-
与
where不同,let x=e in e'可以在表达式内部使用。 (但是,您在这里并不需要它。)