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 -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -