Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在编写一个小函数,它可以帮助我摆脱列表的第一个和最后一个元素。这就是我想要做的:
>firstLast::[a]->[a] >firstLast [x] = [ ] >firstLast h:t = [i|i!= head[a] || i!= last[a]]
如您所见,我在这里尝试使用列表理解,但显然我没有正确使用它。
为什么不只是这个?
firstLast::[a]->[a] firstLast [] = [] firstLast [x] = [] firstLast xs = tail (init xs)