SML Error [roundity]

I would like to write one function that extracts only odd numbers from a list. Sort of:

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

But this causes this error:

Operator

and operand disagree [roundness]

+4
source share
1 answer

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

+7
source

Source: https://habr.com/ru/post/1334770/


All Articles