I am writing a small function which can help me get rid of the first and last element of a list. This is what I am trying to do:
>firstLast::[a]->[a]
>firstLast [x] = [ ]
>firstLast h:t = [i|i!= head[a] || i!= last[a]]
As you can see I am trying to use list comprehension here,but apparently I didn't use it properly.
Why not just this?
firstLast::[a]->[a]
firstLast [] = []
firstLast [x] = []
firstLast xs = tail (init xs)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With