September 22, 1999 Strong Typing Slide #24

Type Elaboration Example 4 Continued

                val map = fn : ('a -> 'b) * 'a list -> 'b list

Actually, ML, supports Currying which means that you can define map like this:

        fun map f  []     = []
          | map f (h::t)  = (f h)::(map f t);
                val map = fn : ('a -> 'b) -> ('a list -> 'b list)
        val sqrtall = map sqrt;
                val sqrtall = fn : real list -> real list
        val sqrts = map sqrt [1.0, 2.0, 3.0, 4.0, 5.0];
                val sqrts = [1.0, 1.414, 1.732, 2.0, 2.236] : real list


Next Copyright © 1999 M-J. Dominus