Teen Programmers Unite  
 

 

Return to forum top

SML problem

Posted by cnikolai [send private reply] at May 16, 2003, 04:25:56 PM

I am having a problem with the following SML code; I would like to compare the value of obj with the corresponding second element of the vector tuple elements.

Following is the code:

type 'vType vector = (int * 'vType) list

fun find (v: ?vType vector, obj: ?vType) = #2(hd(v)))(*works*)

fun find2 (v: ?vType vector, obj: ?vType) = obj(*works*)

fun find3 (v: ?vType vector, obj: ?vType) = #1(hd(v)) = 1 (*works*)

fun find4 (v: ?vType vector, obj:?vType) = #2(hd(v)) = obj (*returns error operator and operand don't agree [ubound match] *) domain: ' 'Z * ' 'Z operand: 'vType * 'vType

However, the following code run from another file works and returns true:
val testing = Vector.find(myvector, [1,2,3,4,5]);
val testing2 = Vector.find2(myvector, [1,2,3,4,5]);
val me = (testing = testing2);

Does anyone know what the problem is and how to fix it?

Posted by Psion [send private reply] at May 16, 2003, 08:26:19 PM

Read about equality types and you should have your answer.

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.