Second most recent element of a Haskell list
I am trying to get the second item in a list in Haskell. I would suggest that the best way to do this is to get the head of the tail of the list.
secondMostRecentChoice :: History -> Choice // a choice is just a Bool like Bake | NoBake
secondMostRecentChoice [] = "Not Enough History"
secondMostRecentChoice history =
if ( length history == 1 )
then "Still Not Enough History"
else if (length history >= 2)
then (head [b | (head a,b) <- history]) //Here is the problem
else "Not supposed to be here"
else "Not supposed to be here"
but I am getting this:
Parsing error in template: head
Could it be that "do" is missing?
Why do I need to do do
or is this a false suggestion?
+3
source to share
3 answers