sml - warning in the ML -


can please explain, warning mean?

stdin:18.35 warning: calling polyequal 

and why have "a , not 'a in following statement:

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

this function:

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

thanks in advance

'a means "any type", while ''a means "any type can compared equality". since alreadyvisited function compared x , v using =, x , v need have type supports comparing them equality, type ''a.

the warning means you're comparing 2 values polymorphic type equality.

why produce warning? because it's less efficient comparing 2 values of known types equality.

how rid of warning? changing function work specific type instead of type.

should care warning? not. in cases argue having function can work type more important having efficient code possible, i'd ignore warning.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -