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

Oden – A Functional Programming Language for the Go Ecosystem (Curry On 2016)

Oden – A Functional Programming Language for the Go Ecosystem (Curry On 2016)

This talk will introduce Oden, an experimental, statically typed, functional programming language built for the Go ecosystem. We will look at how Oden aims to leverage the great features of Go — static linking, cross-compilation, goroutines, channels and the great set of libraries and tools — and enable higher-level abstractions, generics and a safer yet more flexible type system.

Oskar Wickström

July 18, 2016
Tweet

More Decks by Oskar Wickström

Other Decks in Programming

Transcript

  1. Oden
    A Functional Programming Language
    for the Go Ecosystem
    Oskar Wickström
    @owickstrom

    View Slide

  2. http://empear.com
    @owickstrom

    View Slide

  3. Agenda
    • Background
    • Project Goals
    • Current State
    • What’s next?
    • Questions
    @owickstrom

    View Slide

  4. Background
    @owickstrom

    View Slide

  5. Things I’ve been thinking about lately
    @owickstrom

    View Slide

  6. I want type-safe functional programming for
    writing web applications.
    @owickstrom

    View Slide

  7. Haskell is a great language.
    @owickstrom

    View Slide

  8. Can we have the safety of Haskell, but in a
    smaller and simpler language?
    @owickstrom

    View Slide

  9. I want fast, "clean slate" compilation as an option.
    @owickstrom

    View Slide

  10. We should optimize for writing code that is
    correct, understandable, and safe to change.
    @owickstrom

    View Slide

  11. We should not optimize for cleverness.
    @owickstrom

    View Slide

  12. Maybe static typing on top of Javascript?
    @owickstrom

    View Slide

  13. Having to write FFI bindings to use libraries is
    cumbersome. Can the compiler do this for us?
    @owickstrom

    View Slide

  14. Can we reuse all the good stuff from Go, but use a
    functional language?
    @owickstrom

    View Slide

  15. Yes, we can!
    @owickstrom

    View Slide

  16. Why Go?
    • Ecosystem of libraries and tools
    • Goroutines, channels
    • Cross-compilation
    • Static linking
    • Simple compile target
    • Fast compiler
    @owickstrom

    View Slide

  17. What I’m missing in Go
    @owickstrom

    View Slide

  18. Expressions over statements
    @owickstrom

    View Slide

  19. Generic Programming
    @owickstrom

    View Slide

  20. Abstraction
    @owickstrom

    View Slide

  21. func (c *dropboxClient) GetFile(accessToken, dropboxSrc, localTarget string) error {
    url : "https://content.dropboxapi.com/ /files/auto" dropboxSrc
    req, err : http.NewRequest("GET", url, nil)
    req.Header.Add("Authorization", "Bearer " accessToken)
    if err ! nil {
    return err
    }
    client : &http.Client{}
    res, err : client.Do(req)
    if err ! nil {
    return err
    }
    if res.StatusCode {
    return ErrNotFound
    }
    if res.StatusCode || res.StatusCode {
    return errors.New("Dropbox request failed: " res.Status)
    }
    f, err : os.Create(localTarget)
    if err ! nil {
    return err
    }
    io.Copy(f, res.Body)
    if err ! nil {
    return err
    }
    return nil
    }
    @owickstrom

    View Slide

  22. func (c *dropboxClient) GetFile(accessToken, dropboxSrc, localTarget string) error {
    url : "https://content.dropboxapi.com/ /files/auto" dropboxSrc
    req, err : http.NewRequest("GET", url, nil)
    req.Header.Add("Authorization", "Bearer " accessToken)
    if err ! nil {
    return err
    }
    client : &http.Client{}
    res, err : client.Do(req)
    if err ! nil {
    return err
    }
    if res.StatusCode {
    return ErrNotFound
    }
    if res.StatusCode || res.StatusCode {
    return errors.New("Dropbox request failed: " res.Status)
    }
    f, err : os.Create(localTarget)
    if err ! nil {
    return err
    }
    io.Copy(f, res.Body)
    if err ! nil {
    return err
    }
    return nil
    }
    @owickstrom

    View Slide

  23. if err ! nil {
    return err
    }
    @owickstrom

    View Slide

  24. ...
    f, err : os.Create(localTarget)
    if err ! nil {
    return err
    }
    io.Copy(f, res.Body)
    if err ! nil {
    return err
    }
    return nil
    }
    @owickstrom

    View Slide

  25. Project Goals
    @owickstrom

    View Slide

  26. Use Go as a platform
    @owickstrom

    View Slide

  27. Avoid cleverness, prefer clarity
    @owickstrom

    View Slide

  28. Expressions over statements
    @owickstrom

    View Slide

  29. Support generic programming
    @owickstrom

    View Slide

  30. Support good abstractions
    @owickstrom

    View Slide

  31. Type inference
    @owickstrom

    View Slide

  32. Immutability by default
    @owickstrom

    View Slide

  33. Pattern matching
    @owickstrom

    View Slide

  34. Exhaustiveness checking
    @owickstrom

    View Slide

  35. Simple interoperability with Go
    @owickstrom

    View Slide

  36. Fun!
    @owickstrom

    View Slide

  37. Open-source from the beginning
    @owickstrom

    View Slide

  38. Figure: MVP Pyramid
    @owickstrom

    View Slide

  39. Current State
    @owickstrom

    View Slide

  40. Hello World
    package main
    main() println("Hello World")
    @owickstrom

    View Slide

  41. Operators
    !true
    -
    *
    /
    ( - ) /
    * -( )
    !
    "Foo" "Bar"
    false && (true || ( ))
    @owickstrom

    View Slide

  42. Operator Desugaring
    Operator Protocol Method
    - Num Negate
    ! Logical Not
    Num Add
    - Num Subtract
    * Num Multiply
    / Num Divide
    && Logical Conjunction
    || Logical Disjunction
    Monoid Apply
    @owickstrom

    View Slide

  43. No custom operators
    @owickstrom

    View Slide

  44. No macros
    @owickstrom

    View Slide

  45. Curried Functions
    plus(x, y) x y
    twice(f, x) f(f(x))
    plusTwenty twice(plus( ))
    forty plusTwenty( )
    @owickstrom

    View Slide

  46. Curried Functions with Type Signatures
    plus : int - int - int
    plus(x, y) x y
    twice : forall a. (a - a) - a - a
    twice(f, x) f(f(x))
    plusTwenty : int - int
    plusTwenty twice(plus( ))
    forty : int
    forty plusTwenty( )
    @owickstrom

    View Slide

  47. Imports from Go
    package main
    import html
    main() {
    println(html.EscapeString("Simon & Garfunkel"))
    // Simon & Garfunkel
    }
    @owickstrom

    View Slide

  48. Imports from Go
    package main
    import foreign "html"
    main() {
    println(html.EscapeString("Simon & Garfunkel"))
    // Simon & Garfunkel
    }
    @owickstrom

    View Slide

  49. Records
    sweden {
    official "Kingdom Of Sweden",
    population ,
    capital "Stockholm"
    }
    usa {
    official "United States of America",
    population ,
    capital "Washington D.C."
    }
    @owickstrom

    View Slide

  50. Record Types
    sweden : {
    official : string,
    population : int,
    capital : string
    }
    @owickstrom

    View Slide

  51. Records and Row Polymorphism
    fullName(person)
    person.firstName " " person.lastName
    @owickstrom

    View Slide

  52. Records and Row Polymorphism
    fullName : forall r.
    {
    firstName : string,
    lastName : string
    | r
    }
    - string
    @owickstrom

    View Slide

  53. Protocols
    Spoiler: Very similar to type classes
    @owickstrom

    View Slide

  54. Protocols
    impl Monoid({ x: int, y: int }) {
    Apply(p , p ) {
    x p .x p .x,
    y p .y p .y
    }
    Identity { x , y }
    }
    @owickstrom

    View Slide

  55. Protocols
    position { x , y }
    distance { x , y }
    target Monoid::Apply(position, distance)
    @owickstrom

    View Slide

  56. Protocols
    position { x , y }
    distance { x , y }
    target position distance
    @owickstrom

    View Slide

  57. Procotols are not simple
    @owickstrom

    View Slide

  58. That’s not all
    @owickstrom

    View Slide

  59. Finding more information
    @owickstrom

    View Slide

  60. oden-lang.org
    @owickstrom

    View Slide

  61. oden-lang.org/user-guide/latest/
    @owickstrom

    View Slide

  62. playground.oden-lang.org
    @owickstrom

    View Slide

  63. @odenlang
    @owickstrom

    View Slide

  64. What’s next?
    @owickstrom

    View Slide

  65. Thank you!
    @owickstrom

    View Slide