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

Types in ML-Inspired Languages

nt591
July 31, 2019
200

Types in ML-Inspired Languages

Learning about types via the OCaml and Elm

nt591

July 31, 2019
Tweet

Transcript

  1. What is ML? No, not machine learning • “Meta Language”

    • Originally designed as a language to build a theorem prover by Robin Milner • Strong, static typing • Enables powerful type inference via the Hindley-Milner algorithm • We’ll focus on those last two pieces in modern implementations • Code samples will be in OCaml
  2. Type Inference • Type inference refers to the methods that

    allow a machine to understand and enforce a type used in a function without the programmer actually declaring a type signature • Allows the compiler to enforce types by checking all usages of functions and their type signatures before runtime
  3. Parametric Polymorphism • Similar to generics in other languages •

    Given all the information at hand, the computer cannot tell exactly what type is required, therefore it must work for any type a’ and return any type b’
  4. Currying and Partial Application • A curried function is a

    function that takes multiple arguments before executing, but accepts one argument at a time.
  5. Currying and Partial Application Typically, you get both for free

    and safely in typed, functional languages. All functions are curried by default.
  6. Advanced Types: Type Aliases A type alias, or type synonym,

    is a new name for an existing type. This opens the door for more expressive domain modeling
  7. Type Aliases - records Records are a data structure in

    many languages designed to hold multiple pieces of data (like tuples!) but with named fields and accessors
  8. Algebraic Data Types - Sum Types (aka Union Types) •

    A type that represents a limited variety of arbitrary, user defined types
  9. Algebraic Data Types - Constructors with Data • Our types

    can hold onto data • Note the * in definition - refers to a “product type”
  10. If you want to learn more Effective ML by Yaron

    Minsky • https://blog.janestreet.com/effective-ml-revisited/ • https://blog.janestreet.com/effective-ml-video/ Domain Modeling Made Functional • https://fsharpforfunandprofit.com/ddd/ Why Type-First Development Matters • http://tomasp.net/blog/type-first-development.aspx/