0

I'm writing this function on SML. It is supposed to take a list of possible first name variations (my name is Victoria, so V, Vic, Vicky, etc.) and create records of {altname1, middle, last}, {alt2, middle, last}.

So here's my code:

fun similar_names (substits:, name) = 
    let 
    val {first=n1, second=n2, third=n3} = name
    fun name_constructor (altnames:string list, acc) =
        case altnames of 
        [] => acc
         |  a::aa  => {first=a, second=n2, third=n3}::acc
    in 
    name_constructor( get_substitutions2(substits, n1),name)

    end

get_substitutions2 will just give a list of all the possible variations of a first name (ie: string list), and it works.

The error I'm getting is:

a02.sml:65.2-65.58 Error: operator and operand don't agree [tycon mismatch]
  operator domain: string list * {first:string, second:'Z, third:'Y} list
  operand:         string list * {first:string, second:'Z, third:'Y}
  in expression:
    name_constructor (get_substitutions2 (substits,n1),name)

I don't understand why it's going between record list and record alone. Could you help?

Victoria Ruiz
  • 4,913
  • 3
  • 23
  • 40
  • Probably a typo or copy/paste thing but the compiler doesn't like the dangling colon in `(substits:, name) ...)`. – Brian Feb 01 '13 at 16:24

1 Answers1

5

name is only one record, but name_constructor expects acc to be a list (since you say ::acc).
Try

name_constructor(get_substitutions2(substits, n1), [name])
molbdnilo
  • 64,751
  • 3
  • 43
  • 82