Datatype events = enter of string * real | exit of string *real;
So i have this Datatype and i have to write a function that takes a list of events as input and return that list sorted by the real part of events. I tried to write some functions but didnt come up with anything good, any ideas?
this is the code i tried:
val rec ordina = fn
[] => []
|v1::v2::l => if (#2(v2)) > (#2(v1))
then ordina (v1::l)
else oridna (v2::1);
Errors i got:
poly: error: Can't find a fixed record type. Found near #2
poly: error: Can't find a fixed record type. Found near #2
#2macro works on tuples, butEnter (s, r)andExit (s, r)are not directly tuples. You should make a getter function like I suggest in my answer below. Whether you use pattern matching entirely, like I suggest, or you writefun get_... (Enter pair) = #2 pair | ...are both options. - sshine