can somebody please explain, what does this warning mean?
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 function:
fun alreadyVisited(v, []) = false
| alreadyVisited(v, x::xs) = if(x=v) then true
else alreadyVisited(v, xs);
thanks in advance
'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.