Slide 1

Slide 1 text

Modularity à la ML Ionuț G. Stan — igstan.ro — [email protected]

Slide 2

Slide 2 text

• Software Developer at • Worked with Scala for the past 5 years • FP, programming languages, compilers • Mostly-tech blog at igstan.ro About Me

Slide 3

Slide 3 text

Why ML?

Slide 4

Slide 4 text

Why ML

Slide 5

Slide 5 text

Why ML

Slide 6

Slide 6 text

A Taste of Standard ML

Slide 7

Slide 7 text

structure Option = struct datatype 'a option = NONE | SOME of 'a fun map option f = case option of NONE => NONE | SOME a => SOME (f a) end

Slide 8

Slide 8 text

structure Option = struct datatype 'a option = NONE | SOME of 'a fun map option f = case option of NONE => NONE | SOME a => SOME (f a) end

Slide 9

Slide 9 text

structure Option = struct datatype 'a option = NONE | SOME of 'a fun map option f = case option of NONE => NONE | SOME a => SOME (f a) end

Slide 10

Slide 10 text

structure Option = struct datatype 'a option = NONE | SOME of 'a fun map option f = case option of NONE => NONE | SOME a => SOME (f a) end

Slide 11

Slide 11 text

structure Option = struct datatype 'a option = NONE | SOME of 'a fun map option f = case option of NONE => NONE | SOME a => SOME (f a) end

Slide 12

Slide 12 text

structure Option = struct datatype 'a option = NONE | SOME of 'a fun map f f = case option of NONE => NONE | SOME a => SOME (f a) end

Slide 13

Slide 13 text

structure Option = struct datatype 'a option = NONE | SOME of 'a fun map f option = case option of NONE => NONE | SOME a => SOME (f a) end

Slide 14

Slide 14 text

structure Option = struct datatype 'a option = NONE | SOME of 'a fun map f option = case option of NONE => NONE | SOME a => SOME (f a) end

Slide 15

Slide 15 text

structure Option = struct datatype 'a option = NONE | SOME of 'a fun map f option = case option of NONE => NONE | SOME a => SOME (f a) end

Slide 16

Slide 16 text

structure Option = struct datatype 'a option = NONE | SOME of 'a fun map f option = case option of NONE => NONE | SOME a => SOME (f a) end

Slide 17

Slide 17 text

$ sml - datatype 'a option = … NONE … | 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

Slide 18

Slide 18 text

$ sml - datatype 'a option = … NONE … | 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

Slide 19

Slide 19 text

$ sml - datatype 'a option = … NONE … | 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

Slide 20

Slide 20 text

$ sml - datatype 'a option = … NONE … | 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

Slide 21

Slide 21 text

$ sml - datatype 'a option = … NONE … | 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

Slide 22

Slide 22 text

$ sml - datatype 'a option = … NONE … | 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

Slide 23

Slide 23 text

$ sml - datatype 'a option = … NONE … | 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

Slide 24

Slide 24 text

$ sml - datatype 'a option = … NONE … | 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

Slide 25

Slide 25 text

$ sml - datatype 'a option = … NONE … | 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

Slide 26

Slide 26 text

Modules

Slide 27

Slide 27 text

structure Option = struct datatype 'a option = NONE | SOME of 'a fun map f option = case option of NONE => NONE | SOME a => SOME (f a) end

Slide 28

Slide 28 text

structure Option = struct datatype 'a option = NONE | SOME of 'a fun map f option = case option of NONE => NONE | SOME a => SOME (f a) end

Slide 29

Slide 29 text

structure Option = struct datatype 'a option = NONE | SOME of 'a fun map f option = case option of NONE => NONE | SOME a => SOME (f a) end

Slide 30

Slide 30 text

structure Option = struct datatype 'a option = NONE | SOME of 'a fun map f option = case option of NONE => NONE | SOME a => SOME (f a) end

Slide 31

Slide 31 text

structure Option = struct datatype 'a option = NONE | SOME of 'a fun map f option = case option of NONE => NONE | SOME a => SOME (f a) end

Slide 32

Slide 32 text

$ sml - use "option.sml"; - - val a = Option.SOME 1; val a = SOME 1 : int Option.option - - Option.map (fn a => a + 1) a; val it = SOME 2 : int Option.option

Slide 33

Slide 33 text

$ sml - use "option.sml"; - - val a = Option.SOME 1; val a = SOME 1 : int Option.option - - Option.map (fn a => a + 1) a; val it = SOME 2 : int Option.option

Slide 34

Slide 34 text

$ sml - use "option.sml"; - - val a = Option.SOME 1; val a = SOME 1 : int Option.option - - Option.map (fn a => a + 1) a; val it = SOME 2 : int Option.option

Slide 35

Slide 35 text

$ sml - use "option.sml"; - - val a = Option.SOME 1; val a = SOME 1 : int Option.option - - Option.map (fn a => a + 1) a; val it = SOME 2 : int Option.option

Slide 36

Slide 36 text

$ sml - use "option.sml"; - - val a = Option.SOME 1; val a = SOME 1 : int Option.option - - Option.map (fn a => a + 1) a; val it = SOME 2 : int Option.option

Slide 37

Slide 37 text

Functors

Slide 38

Slide 38 text

structure IntListSet = struct val empty = [] fun add 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

Slide 39

Slide 39 text

structure IntListSet = struct val empty = [] fun add 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

Slide 40

Slide 40 text

structure IntListSet = struct val empty = [] fun add 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

Slide 41

Slide 41 text

structure IntListSet = struct val empty = [] fun add 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

Slide 42

Slide 42 text

structure IntListSet = struct val empty = [] fun add 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

Slide 43

Slide 43 text

structure IntListSet = struct val empty = [] fun add 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

Slide 44

Slide 44 text

structure IntListSet = struct val empty = [] fun add 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

Slide 45

Slide 45 text

datatype order = LESS | EQUAL | GREATER

Slide 46

Slide 46 text

structure IntListSet = struct val empty = [] fun add 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

Slide 47

Slide 47 text

structure IntListSet = struct val empty = [] fun add 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

Slide 48

Slide 48 text

structure IntListSet = struct val empty = [] fun add 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

Slide 49

Slide 49 text

structure IntListSet = struct val empty = [] fun add 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

Slide 50

Slide 50 text

structure StringListSet = struct val empty = [] fun add 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

Slide 51

Slide 51 text

structure StringListSet = struct val empty = [] fun add 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

Slide 52

Slide 52 text

functor ListSet(Elem : ORD) = struct 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

Slide 53

Slide 53 text

functor ListSet(Elem : ORD) = struct 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

Slide 54

Slide 54 text

In Standard ML, a functor is a module-level function that takes a module as argument and produces a module as a result.

Slide 55

Slide 55 text

Note: There's no relationship between an SML functor and the Functor type-class as defined by the cats or scalaz libraries.

Slide 56

Slide 56 text

functor ListSet(Elem : ORD) = struct 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

Slide 57

Slide 57 text

functor ListSet(Elem : ORD) = struct 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

Slide 58

Slide 58 text

Signatures

Slide 59

Slide 59 text

functor ListSet(Elem : ORD) = struct 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

Slide 60

Slide 60 text

functor ListSet(Elem : ORD) = struct 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

Slide 61

Slide 61 text

functor ListSet(Elem : ORD) = struct 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

Slide 62

Slide 62 text

functor ListSet(Elem : ORD) = struct 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

Slide 63

Slide 63 text

signature ORD = sig type t val compare : t * t -> order end

Slide 64

Slide 64 text

signature ORD = sig type t val compare : t * t -> order end

Slide 65

Slide 65 text

signature ORD = sig type t val compare : t * t -> order end

Slide 66

Slide 66 text

signature ORD = sig type t val compare : t * t -> order end

Slide 67

Slide 67 text

A signature can be seen as the type of a module. It specifies the types and values that a module must define.

Slide 68

Slide 68 text

functor ListSet(Elem : ORD) = struct 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

Slide 69

Slide 69 text

functor ListSet(Elem : ORD) : SET = struct 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

Slide 70

Slide 70 text

functor ListSet(Elem : ORD) : SET = struct 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

Slide 71

Slide 71 text

signature SET = sig structure Key : ORD type t val empty : t val add : t -> key -> t end

Slide 72

Slide 72 text

signature SET = sig type t type key val empty : t val add : t -> key -> t end

Slide 73

Slide 73 text

signature SET = sig type t type key val empty : t val add : t -> key -> t end

Slide 74

Slide 74 text

signature SET = sig type t type key val empty : t val add : t -> key -> t end

Slide 75

Slide 75 text

signature SET = sig type t type key val empty : t val add : t -> key -> t end

Slide 76

Slide 76 text

signature SET = sig type t type key val empty : t val add : t -> key -> t end

Slide 77

Slide 77 text

signature SET = sig type t type key val empty : t val add : t -> key -> t end

Slide 78

Slide 78 text

functor ListSet(Elem : ORD) : SET = struct type t = 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

Slide 79

Slide 79 text

functor ListSet(Elem : ORD) : SET = struct type t = 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

Slide 80

Slide 80 text

structure IntOrd = struct type t = Int.int val compare = Int.compare end structure IntListSet = ListSet(IntOrd) structure StringListSet = ListSet(struct type t = String.string val compare = String.compare end)

Slide 81

Slide 81 text

structure IntOrd = struct type t = Int.int val compare = Int.compare end structure IntListSet = ListSet(IntOrd) structure StringListSet = ListSet(struct type t = String.string val compare = String.compare end)

Slide 82

Slide 82 text

structure IntOrd = struct type t = Int.int val compare = Int.compare end structure IntListSet = ListSet(IntOrd) structure StringListSet = ListSet(struct type t = String.string val compare = String.compare end)

Slide 83

Slide 83 text

Similarities with Scala?

Slide 84

Slide 84 text

Similarities Standard ML Scala

Slide 85

Slide 85 text

Similarities Standard ML Scala structure object

Slide 86

Slide 86 text

Similarities Standard ML Scala structure object signature trait

Slide 87

Slide 87 text

Similarities Standard ML Scala structure object signature trait functor class / def

Slide 88

Slide 88 text

Differences & Limitations

Slide 89

Slide 89 text

Limitations in SML

Slide 90

Slide 90 text

Limitations in SML Q If a functor is like a function, can we pass functors to functors, just like we can pass functions to functions?

Slide 91

Slide 91 text

Limitations in SML Q If a functor is like a 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.

Slide 92

Slide 92 text

Limitations in SML

Slide 93

Slide 93 text

Limitations in SML Q So we can't return functors from functors, either?

Slide 94

Slide 94 text

Limitations in SML Q So we can't return functors from functors, either? A No, we cannot in Standard ML.

Slide 95

Slide 95 text

Limitations in Scala

Slide 96

Slide 96 text

Limitations in Scala Q If Scala classes are the equivalent of SML functors, are they higher-order or not?

Slide 97

Slide 97 text

Limitations in Scala Q If Scala classes are the equivalent 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.

Slide 98

Slide 98 text

Limitations in SML

Slide 99

Slide 99 text

Limitations in SML Q In Scala, we can store objects in variables, pass them to functions or return them from functions. Does SML allow this with structures and functors?

Slide 100

Slide 100 text

Limitations in SML Q In Scala, we can store objects 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.

Slide 101

Slide 101 text

Limitations in SML

Slide 102

Slide 102 text

Limitations in SML Q Why aren't modules first-class values in Standard ML?

Slide 103

Slide 103 text

Limitations in SML Q Why aren't modules first-class values in Standard ML? A Let's see...

Slide 104

Slide 104 text

trait Ord { type T def compare(a: T, b: T): Int }

Slide 105

Slide 105 text

object IntOrd extends Ord { type T = Int def compare(a: T, b: T): Int = a - b }

Slide 106

Slide 106 text

trait Set { type T type K def empty: T def add(set: T, key: K): T }

Slide 107

Slide 107 text

class ListSet(val ord: Ord) extends Set { type K = ord.T type T = List[ord.T] def empty: T = List.empty def add(set: T, key: K): T = ??? }

Slide 108

Slide 108 text

object TwitterClient { object UserSet extends ListSet(UserOrd) def followers(username: String) = { val users: UserSet.T = UserSet.empty // add users and return them users } }

Slide 109

Slide 109 text

object TwitterClient { object UserSet extends ListSet(UserOrd) def followers(username: String) = { val users: UserSet.T = UserSet.empty // add users and return them users } }

Slide 110

Slide 110 text

object TwitterClient { object UserSet extends ListSet(UserOrd) def followers(username: String) = { val users: UserSet.T = UserSet.empty // add users and return them users } }

Slide 111

Slide 111 text

object TwitterClient { object UserSet extends ListSet(UserOrd) def followers(username: String) = { val users = UserSet.empty // add users and return them users } }

Slide 112

Slide 112 text

object TwitterClient { object UserSet extends ListSet(UserOrd) def followers(username: String) = { val users = UserSet.empty // add users and return them users } }

Slide 113

Slide 113 text

object TwitterClient { def followers(username: String) = { object UserSet extends ListSet(UserOrd) val users = UserSet.empty // add users and return them users } }

Slide 114

Slide 114 text

object TwitterClient { def followers(username: String) = { val userSet = new ListSet(UserOrd) val users = UserSet.empty // add users and return them users } }

Slide 115

Slide 115 text

object TwitterClient { def followers(username: String) = { val userSet = new ListSet(UserOrd) val users: UserSet.T = UserSet.empty // add users and return them users } }

Slide 116

Slide 116 text

object TwitterClient { def followers(username: String) = { val userSet = new ListSet(UserOrd) val users: userSet.T = UserSet.empty // add users and return them users } }

Slide 117

Slide 117 text

object TwitterClient { def followers(username: String): List[userSet.ord.T] forSome { val userSet: ListSet } = { val userSet = new ListSet(UserOrd) val users: userSet.T = UserSet.empty // add users and return them users } }

Slide 118

Slide 118 text

object TwitterClient { def followers(username: String): List[userSet.ord.T] forSome { val userSet: ListSet } = { val userSet = new ListSet(UserOrd) val users: userSet.T = UserSet.empty // add users and return them users } }

Slide 119

Slide 119 text

object TwitterClient { import scala.language.existentials def followers(username: String): List[userSet.ord.T] forSome { val userSet: ListSet } = { val userSet = new ListSet(UserOrd) val users: userSet.T = UserSet.empty // add users and return them users } }

Slide 120

Slide 120 text

object TwitterClient { import scala.language.existentials def followers(username: String): userSet.T forSome { val userSet: Set } = { val userSet = new ListSet(UserOrd) val users: userSet.T = UserSet.empty // add users and return them users } }

Slide 121

Slide 121 text

object TwitterClient { import scala.language.existentials def followers(username: String): Set#T = { val userSet = new ListSet(UserOrd) val users: userSet.T = UserSet.empty // add users and return them users } }

Slide 122

Slide 122 text

Limitations in SML Q Why aren't modules first-class values in Standard ML?

Slide 123

Slide 123 text

Limitations in SML Q Why aren't modules first-class values in 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.

Slide 124

Slide 124 text

Other Differences

Slide 125

Slide 125 text

Other Differences • SML's modules are not (mutually) recursive, while Scala's objects and classes are.

Slide 126

Slide 126 text

Other Differences • SML's modules are not (mutually) recursive, while Scala's objects and classes are. • Because objects, traits and classes are values, they're also types in Scala.

Slide 127

Slide 127 text

Other Differences • SML's modules are not (mutually) recursive, while 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.

Slide 128

Slide 128 text

Other Differences • SML's modules are not (mutually) recursive, while 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.

Slide 129

Slide 129 text

Dependency Injection

Slide 130

Slide 130 text

Dependency Injection

Slide 131

Slide 131 text

Dependency Injection • Functor params look a lot like constructor injection.

Slide 132

Slide 132 text

Dependency Injection • Functor params look a lot like constructor injection. • The Reader monad is usually advocated by FP people for doing "functional" DI.

Slide 133

Slide 133 text

Dependency Injection • Functor params look a lot like constructor injection. • The Reader monad is usually advocated by FP people for doing "functional" DI. • But Reader only injects values, not types.

Slide 134

Slide 134 text

Dependency Injection • Functor params look a lot like constructor 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.

Slide 135

Slide 135 text

Dependency Injection • Functor params look a lot like constructor 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.

Slide 136

Slide 136 text

Dependency Injection • We should distinguish between:

Slide 137

Slide 137 text

Dependency Injection • We should distinguish between: • static dependencies: dependencies are known at compile-time. Employ constructor injection or type-classes (coherent implicit params).

Slide 138

Slide 138 text

Dependency Injection • We should distinguish between: • static dependencies: 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.

Slide 139

Slide 139 text

Scala's object system can and should be seen as a first-class module system.

Slide 140

Slide 140 text

Thank You!

Slide 141

Slide 141 text

Questions!