Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Let the Scala compiler work with you

Let the Scala compiler work with you

Programming in some languages can feel like you’re working for the compiler - the type checker is naggy, the type system limiting, and much of your code is extraneous. This is backwards. The compiler should be working for you, helping you check your code, allowing you to express the abstractions you want, and enabling you to write clean, beautiful code. In Scala we are lucky to have such a compiler. In this talk we will explore a variety of techniques, libraries, and compiler plugins for Scala that demonstrate the utility of having a compiler that works for you.

Adelbert Chang

March 23, 2017
Tweet

More Decks by Adelbert Chang

Other Decks in Programming

Transcript

  1. 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
  2. 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
  3. 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:
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. • Found hole: _ :: [Char] -> IO () In

    the expression: do _ "hello, world" Valid substitutions include ps :: String -> IO () putStrLn :: String -> IO () putStr :: String -> IO ()
  10. Other examples ▶ Friendly compile errors (Elm, Rust, Dotty) ▶

    Type holes (Haskell, Idris): ask the compiler what we need and what we have
  11. 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
  12. 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
  13. 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
  14. EOF