Returning the last element of a list in haskell using recursion -


how last element in list in haskell? have written of code below:

lastlist :: list -> lastlist lst =    case lst of        cons x xs -> lastlist xs        cons _ xs -> lastlist xs        empty    -> error "lastlist of empty list" 

how do without using of built in functions?

you have check when element cons empty:

lastlist :: list -> lastlist lst =    case lst of        cons x empty -> x        cons _ xs    -> lastlist xs        empty        -> error "lastlist of empty list" 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -