| SOME of 'a; datatype 'a option = NONE | SOME of 'a - - fun map f option = … case option of … NONE => NONE … | SOME a => SOME (f a); val map = fn : ('a -> 'b) -> 'a option -> 'b option - - val a = SOME 1; val a = SOME 1 : int option - - map (fn a => a + 1) a; val it = SOME 2 : int option
| SOME of 'a; datatype 'a option = NONE | SOME of 'a - - fun map f option = … case option of … NONE => NONE … | SOME a => SOME (f a); val map = fn : ('a -> 'b) -> 'a option -> 'b option - - val a = SOME 1; val a = SOME 1 : int option - - map (fn a => a + 1) a; val it = SOME 2 : int option
| SOME of 'a; datatype 'a option = NONE | SOME of 'a - - fun map f option = … case option of … NONE => NONE … | SOME a => SOME (f a); val map = fn : ('a -> 'b) -> 'a option -> 'b option - - val a = SOME 1; val a = SOME 1 : int option - - map (fn a => a + 1) a; val it = SOME 2 : int option
| SOME of 'a; datatype 'a option = NONE | SOME of 'a - - fun map f option = … case option of … NONE => NONE … | SOME a => SOME (f a); val map = fn : ('a -> 'b) -> 'a option -> 'b option - - val a = SOME 1; val a = SOME 1 : int option - - map (fn a => a + 1) a; val it = SOME 2 : int option
| SOME of 'a; datatype 'a option = NONE | SOME of 'a - - fun map f option = … case option of … NONE => NONE … | SOME a => SOME (f a); val map = fn : ('a -> 'b) -> 'a option -> 'b option - - val a = SOME 1; val a = SOME 1 : int option - - map (fn a => a + 1) a; val it = SOME 2 : int option
| SOME of 'a; datatype 'a option = NONE | SOME of 'a - - fun map f option = … case option of … NONE => NONE … | SOME a => SOME (f a); val map = fn : ('a -> 'b) -> 'a option -> 'b option - - val a = SOME 1; val a = SOME 1 : int option - - map (fn a => a + 1) a; val it = SOME 2 : int option
| SOME of 'a; datatype 'a option = NONE | SOME of 'a - - fun map f option = … case option of … NONE => NONE … | SOME a => SOME (f a); val map = fn : ('a -> 'b) -> 'a option -> 'b option - - val a = SOME 1; val a = SOME 1 : int option - - map (fn a => a + 1) a; val it = SOME 2 : int option
| SOME of 'a; datatype 'a option = NONE | SOME of 'a - - fun map f option = … case option of … NONE => NONE … | SOME a => SOME (f a); val map = fn : ('a -> 'b) -> 'a option -> 'b option - - val a = SOME 1; val a = SOME 1 : int option - - map (fn a => a + 1) a; val it = SOME 2 : int option
| SOME of 'a; datatype 'a option = NONE | SOME of 'a - - fun map f option = … case option of … NONE => NONE … | SOME a => SOME (f a); val map = fn : ('a -> 'b) -> 'a option -> 'b option - - val a = SOME 1; val a = SOME 1 : int option - - map (fn a => a + 1) a; val it = SOME 2 : int option
set elem = case set of [] => [elem] | head :: tail => case Int.compare (head, elem) of LESS => head :: (add tail elem) | EQUAL => set | GREATER => elem :: set end
set elem = case set of [] => [elem] | head :: tail => case Int.compare (head, elem) of LESS => head :: (add tail elem) | EQUAL => set | GREATER => elem :: set end
set elem = case set of [] => [elem] | head :: tail => case Int.compare (head, elem) of LESS => head :: (add tail elem) | EQUAL => set | GREATER => elem :: set end
set elem = case set of [] => [elem] | head :: tail => case Int.compare (head, elem) of LESS => head :: (add tail elem) | EQUAL => set | GREATER => elem :: set end
set elem = case set of [] => [elem] | head :: tail => case Int.compare (head, elem) of LESS => head :: (add tail elem) | EQUAL => set | GREATER => elem :: set end
set elem = case set of [] => [elem] | head :: tail => case Int.compare (head, elem) of LESS => head :: (add tail elem) | EQUAL => set | GREATER => elem :: set end
set elem = case set of [] => [elem] | head :: tail => case Int.compare (head, elem) of LESS => head :: (add tail elem) | EQUAL => set | GREATER => elem :: set end
set elem = case set of [] => [elem] | head :: tail => case Int.compare (head, elem) of LESS => head :: (add tail elem) | EQUAL => set | GREATER => elem :: set end
set elem = case set of [] => [elem] | head :: tail => case Int.compare (head, elem) of LESS => head :: (add tail elem) | EQUAL => set | GREATER => elem :: set end
set elem = case set of [] => [elem] | head :: tail => case Int.compare (head, elem) of LESS => head :: (add tail elem) | EQUAL => set | GREATER => elem :: set end
set elem = case set of [] => [elem] | head :: tail => case Int.compare (head, elem) of LESS => head :: (add tail elem) | EQUAL => set | GREATER => elem :: set end
set elem = case set of [] => [elem] | head :: tail => case String.compare (head, elem) of LESS => head :: (add tail elem) | EQUAL => set | GREATER => elem :: set end
set elem = case set of [] => [elem] | head :: tail => case String.compare (head, elem) of LESS => head :: (add tail elem) | EQUAL => set | GREATER => elem :: set end
fun add set elem = case set of [] => [elem] | head :: tail => case Elem.compare (head, elem) of LESS => head :: (add tail elem) | EQUAL => set | GREATER => elem :: set end
fun add set elem = case set of [] => [elem] | head :: tail => case Elem.compare (head, elem) of LESS => head :: (add tail elem) | EQUAL => set | GREATER => elem :: set end
fun add set elem = case set of [] => [elem] | head :: tail => case Elem.compare (head, elem) of LESS => head :: (add tail elem) | EQUAL => set | GREATER => elem :: set end
fun add set elem = case set of [] => [elem] | head :: tail => case Elem.compare (head, elem) of LESS => head :: (add tail elem) | EQUAL => set | GREATER => elem :: set end
fun add set elem = case set of [] => [elem] | head :: tail => case Elem.compare (head, elem) of LESS => head :: (add tail elem) | EQUAL => set | GREATER => elem :: set end
fun add set elem = case set of [] => [elem] | head :: tail => case Elem.compare (head, elem) of LESS => head :: (add tail elem) | EQUAL => set | GREATER => elem :: set end
fun add set elem = case set of [] => [elem] | head :: tail => case Elem.compare (head, elem) of LESS => head :: (add tail elem) | EQUAL => set | GREATER => elem :: set end
fun add set elem = case set of [] => [elem] | head :: tail => case Elem.compare (head, elem) of LESS => head :: (add tail elem) | EQUAL => set | GREATER => elem :: set end
fun add set elem = case set of [] => [elem] | head :: tail => case Elem.compare (head, elem) of LESS => head :: (add tail elem) | EQUAL => set | GREATER => elem :: set end
= [] fun add set elem = case set of [] => [elem] | head :: tail => case Elem.compare (head, elem) of LESS => head :: (add tail elem) | EQUAL => set | GREATER => elem :: set end
= [] fun add set elem = case set of [] => [elem] | head :: tail => case Elem.compare (head, elem) of LESS => head :: (add tail elem) | EQUAL => set | GREATER => elem :: set end
= Elem.t list type key = Elem.t val empty = [] fun add set elem = case set of [] => [elem] | head :: tail => case Elem.compare (head, elem) of LESS => head :: (add tail elem) | EQUAL => set | GREATER => elem :: set end
= Elem.t list type key = Elem.t val empty = [] fun add set elem = case set of [] => [elem] | head :: tail => case Elem.compare (head, elem) of LESS => head :: (add tail elem) | EQUAL => set | GREATER => elem :: set end
= Int.compare end structure IntListSet = ListSet(IntOrd) structure StringListSet = ListSet(struct type t = String.string val compare = String.compare end)
= Int.compare end structure IntListSet = ListSet(IntOrd) structure StringListSet = ListSet(struct type t = String.string val compare = String.compare end)
= Int.compare end structure IntListSet = ListSet(IntOrd) structure StringListSet = ListSet(struct type t = String.string val compare = String.compare end)
function, can we pass functors to functors, just like we can pass functions to functions? A No. Standard ML does not have higher-order functors. OCaml and some other ML dialects have it, though.
of SML functors, are they higher-order or not? A They're not. One cannot, save for reflection, pass classes as arguments to classes or produce classes from classes.
in variables, pass them to functions or return them from functions. Does SML allow this with structures and functors? A No. In Standard ML, modules are not first-class. Values and modules form two different, separate languages — the so- called core and module languages.
Standard ML? A Having types as components of a signature seems to require the notion of dependent types if the language were to support first-class modules. Scala has path-dependent types.
Scala's objects and classes are. • Because objects, traits and classes are values, they're also types in Scala. • Objects come with a concept of this (open recursion), SML modules do not.
Scala's objects and classes are. • Because objects, traits and classes are values, they're also types in Scala. • Objects come with a concept of this (open recursion), SML modules do not. • SML modules allow some sort of inheritance, but not overriding, as there's no this.
injection. • The Reader monad is usually advocated by FP people for doing "functional" DI. • But Reader only injects values, not types. • A functor-like approach, i.e., constructor injection, is still useful.
injection. • The Reader monad is usually advocated by FP people for doing "functional" DI. • But Reader only injects values, not types. • A functor-like approach, i.e., constructor injection, is still useful. • Scala alternative: implicit params.
dependencies are known at compile-time. Employ constructor injection or type-classes (coherent implicit params). • dynamic dependencies: dependencies are known at runtime. Employ constructor injection, implicit params, Reader monad.