Slide 1

Slide 1 text

Let the Scala compiler work for with you Adelbert Chang

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Type systems: communicating with the compiler ▶ The type system is our way of talking to the compiler

Slide 4

Slide 4 text

Type systems: communicating with the compiler ▶ The type system is our way of talking to the compiler ▶ The more expressive the type system, the more we can say to the compiler

Slide 5

Slide 5 text

Type systems: communicating with the compiler ▶ The type system is our way of talking to the compiler ▶ The more expressive the type system, the more we can say to the compiler ▶ The more the compiler knows, the more it can help

Slide 6

Slide 6 text

Type systems: communicating with the compiler ▶ The type system is our way of talking to the compiler ▶ The more expressive the type system, the more we can say to the compiler ▶ The more the compiler knows, the more it can help ▶ Scala examples:

Slide 7

Slide 7 text

Type systems: communicating with the compiler ▶ The type system is our way of talking to the compiler ▶ The more expressive the type system, the more we can say to the compiler ▶ The more the compiler knows, the more it can help ▶ Scala examples: ▶ Implicits and type classes - proof search

Slide 8

Slide 8 text

Type systems: communicating with the compiler ▶ The type system is our way of talking to the compiler ▶ The more expressive the type system, the more we can say to the compiler ▶ The more the compiler knows, the more it can help ▶ Scala examples: ▶ Implicits and type classes - proof search ▶ Path-dependent types - computing types

Slide 9

Slide 9 text

Type systems: communicating with the compiler ▶ The type system is our way of talking to the compiler ▶ The more expressive the type system, the more we can say to the compiler ▶ The more the compiler knows, the more it can help ▶ Scala examples: ▶ Implicits and type classes - proof search ▶ Path-dependent types - computing types ▶ Literal and singleton types

Slide 10

Slide 10 text

Type systems: communicating with the compiler ▶ The type system is our way of talking to the compiler ▶ The more expressive the type system, the more we can say to the compiler ▶ The more the compiler knows, the more it can help ▶ Scala examples: ▶ Implicits and type classes - proof search ▶ Path-dependent types - computing types ▶ Literal and singleton types ▶ Refinement types and (G)ADTs - modeling domains

Slide 11

Slide 11 text

Live coding!

Slide 12

Slide 12 text

Example: Compiler Errors for Humans1 1http://elm-lang.org/blog/compiler-errors-for-humans

Slide 13

Slide 13 text

Example: Compiler Errors for Humans1 Figure 1: https://blog.rust-lang.org/2016/08/10/Shape-of-errors-to-come.html 1http://elm-lang.org/blog/compiler-errors-for-humans

Slide 14

Slide 14 text

Example: type holes2 2https://phabricator.haskell.org/D3361

Slide 15

Slide 15 text

Example: type holes2 ps :: String -> IO () ps = putStrLn ps2 :: a -> IO () ps2 ignored = putStrLn "hello, world" main :: IO () main = _ "hello, world" 2https://phabricator.haskell.org/D3361

Slide 16

Slide 16 text

• Found hole: _ :: [Char] -> IO () In the expression: do _ "hello, world" Valid substitutions include ps :: String -> IO () putStrLn :: String -> IO () putStr :: String -> IO ()

Slide 17

Slide 17 text

Other examples ▶ Friendly compile errors (Elm, Rust, Dotty)

Slide 18

Slide 18 text

Other examples ▶ Friendly compile errors (Elm, Rust, Dotty) ▶ Type holes (Haskell, Idris): ask the compiler what we need and what we have

Slide 19

Slide 19 text

Other examples ▶ Friendly compile errors (Elm, Rust, Dotty) ▶ Type holes (Haskell, Idris): ask the compiler what we need and what we have ▶ Affine and linear types (Rust, ATS): track ownership and lifetime of variables

Slide 20

Slide 20 text

Other examples ▶ Friendly compile errors (Elm, Rust, Dotty) ▶ Type holes (Haskell, Idris): ask the compiler what we need and what we have ▶ Affine and linear types (Rust, ATS): track ownership and lifetime of variables ▶ Refinement types (Liquid Haskell): refine existing types with logical predicates

Slide 21

Slide 21 text

Other examples ▶ Friendly compile errors (Elm, Rust, Dotty) ▶ Type holes (Haskell, Idris): ask the compiler what we need and what we have ▶ Affine and linear types (Rust, ATS): track ownership and lifetime of variables ▶ Refinement types (Liquid Haskell): refine existing types with logical predicates ▶ Dependent types (Idris, Agda, Coq): types are values

Slide 22

Slide 22 text

EOF