0
votes

Working in ML I have a recursive function, written in if, then, else style. The function has two base cases, Null List, and Null tail of list. The first base case is easy to convert to pattern matching style.

if(Null L) then false

becomes

fun oddNum(nil) = false 

I am not sure how to write the other base case in pattern matching style.

else if (Null tl(L)) then true

I have tried this

| oddNum(nil(tl(L)) = true

My problem is that I do not know how to declare the list L as x::xs, before I write my second base case "| oddNum(nil(tl(L)) = true"

1

1 Answers

4
votes
fun oddNum nil = false
  | oddNum (_::nil) = true
  | oddNum (_::_::xs) = oddNum xs