39

Can somebody please explain, what does this warning means?

stdIn:18.35 Warning: calling polyEqual

and why do I have "a and not 'a in the following statement:

val alreadyVisited = fn : ''a * ''a list -> bool

this is my function:

fun alreadyVisited(v, []) = false
    | alreadyVisited(v, x::xs) = if(x=v) then true
        else alreadyVisited(v, xs);

1 Answer 1

58

'a means "any type", while ''a means "any type that can be compared for equality". Since your alreadyVisited function compared x and v using =, x and v need to have a type that supports comparing them for equality, so you get the type ''a.

The warning means that you're comparing two values with polymorphic type for equality.

Why does this produce a warning? Because it's less efficient than comparing two values of known types for equality.

How do you get rid of the warning? By changing your function to only work with a specific type instead of any type.

Should you care about the warning? Probably not. In most cases I would argue that having a function that can work for any type is more important than having the most efficient code possible, so I'd just ignore the warning.

1
  • I get the same warning in the, perhaps simplified, case: fun some_fun((*stuff*)) = []; likely because the compiler cannot infer the type of an empty list. Putting, say, a string in the list makes the warning go away.
    – brntsllvn
    Sep 15, 2016 at 0:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.