1
votes

I have this function that results a string list:

fun get_substitutions1 ([],_) = []
| get_substitutions1 (x::xs,s) = case all_except_option(s,x) of
    NONE     => []  @get_substitutions1(xs,s)
  | SOME lst => lst @get_substitutions1(xs,s)

And this function that takes a string list list and a type:

fun similar_names(slist,full_name:{first:string,middle:string,last:string})=
let
fun aux(slist,acc)=
case full_name of
{first=a,middle=b,last=c} => case get_substitutions1(slist,a) of
[] => full_name::acc
| x::xs'  => full_name::  aux(xs',{first=x,middle=b,last=c}::acc)

in aux(slist,[])
end

And i get an error:

Error: operator and operand don't agree.

operator domain: string list list * 
                 {first:string, last:string, middle:string} list
operand:         string list * 
                 {first:string, last:string, middle:string} list
in expression:
   aux (xs',{first=x,middle=b,last=c} :: acc)

Is there any other way?

1

1 Answers

4
votes

Well first of all you might wan't to indent your code so that it is readable.

It is quite obvious why you get the error you do. The function

fun get_substitutions1 ([],_) = []
  | get_substitutions1 (x::xs,s) =
    case all_except_option(s,x) of
      NONE => []@get_substitutions1(xs,s)
    | SOME lst => lst @get_substitutions1(xs,s)

has the type

val get_substitutions1 = fn : ''a list list * ''a -> ''a list

and you are trying to use the result of this function in your inner case expression where you take the tail of the returned list (type 'a list) and use them in the recursive function call.

fun similar_names(slist,full_name:{first:string,middle:string,last:string})=
    let
      fun aux(slist,acc)=
          case full_name of
            {first=a,middle=b,last=c} =>
            case get_substitutions1(slist,a) of
              [] => full_name::acc
            | x::xs'  => full_name::  aux(xs',{first=x,middle=b,last=c}::acc)
    in aux(slist,[])
    end

However since your first argument of aux is used in get_substitutions1, that argument must be of type 'a list list, but the xs' you use down in the recursive call is only of type 'a list.