Search code examples
functiontypessmlml

language ML function val a’ * a’ * int -> bool


In ML language

Suppose f(x,y,z) is a function. Give an example of a definition of f that would cause the argument of f to have the type: a’ * a’ * int.

sample code

fun f1 (x,y,z) =  z<5 ;

val f1 = fn : 'a * 'b * int -> bool

how I change this val to a’ * a’ * int -> bool ??


Solution

  • The type:

    a’ * a’ * int -> bool 
    

    means that the function takes three arguments the first is of 'a type, the second also of 'a type and third of type int.

    Your definition:

    fun f1 (x,y,z) =  z<5 ;
    

    is in the right way since it takes a tuple, now in order to restrict the type of x,y to be equal you could write:

    fun f1 (x :'a ,y :'a ,z) =  z<5 ;