4
votes

I'd like to write one function that extracts only the odd numbers from a list. Something like:

fun odd(nil) = nil
  | odd(a::nil) = a
  | odd(a::(b::c)) = a::odd(c);

But it causes this error:

operator and operand don't agree [circularity]

1

1 Answers

7
votes

In your second case odd(a::nil) = a you return a, which is a single element. In the other two cases you return a list. If you change it to odd(a::nil) = [a], so all cases return a list, it works.