tags:

views:

150

answers:

2

I'm getting what seems to be a precedence issue in calling an SML function, substitute:

fun substitute v new (typevar q) = ...

And I am calling this from another function:

fun new_type_vars (typevar v) non_gens = 
                   substitute v new_var() (typevar v)

But I get an error:

    C:/sml/type_checker.sml:22.48-23.44 Error: operator and operand don't agree [tycon mismatch]
      operator domain: type_exp
      operand:         unit -> string
      in expression:
        (substitute v) new_var

Which seems to suggest that it's trying to call (substitute v), and then call the result of that call with argument new_var.

I've tried adding parentheses around the whole thing, but that doesn't help, and when I add parenthesis around the arguments like (v new_var...) it thinks that v is a function application on new_var. What's going on with this function call?

+1  A: 

I don't understand everything, since you don't give all the types of the different operations and variables.

But the general problem you've got is as you already guessed, SML executes the function calls (and binds the variables) from the left side. Here an example:

fun f a:int b:int c:string = ...

f is thus a function of the type int -> int -> string -> ... and implicitly adds the parentheses fun (((f a:int) b:int) c:int) = ...

This means you can use it for example like this:

var f2 = f 3;

And f2 has now the type int -> string -> ...

boutta
+1  A: 

You probably want to change

substitute v new_var() (typevar v)

to

substitute v (new_var()) (typevar v)

(boutta's answer explains why.)

Darius Bacon