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);
funnydman
  • 9,083
  • 4
  • 40
  • 55
rookie
  • 7,723
  • 15
  • 49
  • 59

1 Answers1

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.

sepp2k
  • 363,768
  • 54
  • 674
  • 675
  • 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 '16 at 00:46