我正在编写一个小函数,可以帮我去掉列表的第一个和最后一个元素。我的目标是: >firstLast::[a]->[a] >firstLast [x] = [ ] >firstLast h:t = [i|i!= head[a] || i!= last[a]] 你可以看到,我在这里尝试使用列表推导式,但显然我没有正确地使用它。
firstLast xs@(_:_) = tail (init xs); firstLast _ = []
- daniel gratzerfirstLast (x:xs) = init xs
。 - jake-ferguson