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
Post a Comment