Reputation: 3
I am brand new to learning standard ML. I want to make a function that takes a list/lists of 3 numbers and deletes the middle number and then reverse the order of the two numbers. So if I have a input of (3, 4, 5) then I want to return (5, 3).
This is what I have so far:
fun twiddle [] = [] | twiddle (x::xs) = x::twiddle xs;
I am not sure how to distinguish the middle item of the list and then delete it.
Upvotes: 0
Views: 63
Reputation: 66459
If there are always three numbers, use a pattern matching three elements:
fun twiddle [a,b,c] = [c,a]
Upvotes: 1