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.

Be279c8e94a0825d7c982e745a3b3ba9?s=128

Oskar Wickström

July 18, 2016
Tweet

Transcript

  1. Oden A Functional Programming Language for the Go Ecosystem Oskar

    Wickström @owickstrom
  2. http://empear.com @owickstrom

  3. Agenda • Background • Project Goals • Current State •

    What’s next? • Questions @owickstrom
  4. Background @owickstrom

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

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

  7. Haskell is a great language. @owickstrom

  8. Can we have the safety of Haskell, but in a

    smaller and simpler language? @owickstrom
  9. I want fast, "clean slate" compilation as an option. @owickstrom

  10. We should optimize for writing code that is correct, understandable,

    and safe to change. @owickstrom
  11. We should not optimize for cleverness. @owickstrom

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

  13. Having to write FFI bindings to use libraries is cumbersome.

    Can the compiler do this for us? @owickstrom
  14. Can we reuse all the good stuff from Go, but

    use a functional language? @owickstrom
  15. Yes, we can! @owickstrom

  16. Why Go? • Ecosystem of libraries and tools • Goroutines,

    channels • Cross-compilation • Static linking • Simple compile target • Fast compiler @owickstrom
  17. What I’m missing in Go @owickstrom

  18. Expressions over statements @owickstrom

  19. Generic Programming @owickstrom

  20. Abstraction @owickstrom

  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
  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
  23. if err ! nil { return err } @owickstrom

  24. ... f, err : os.Create(localTarget) if err ! nil {

    return err } io.Copy(f, res.Body) if err ! nil { return err } return nil } @owickstrom
  25. Project Goals @owickstrom

  26. Use Go as a platform @owickstrom

  27. Avoid cleverness, prefer clarity @owickstrom

  28. Expressions over statements @owickstrom

  29. Support generic programming @owickstrom

  30. Support good abstractions @owickstrom

  31. Type inference @owickstrom

  32. Immutability by default @owickstrom

  33. Pattern matching @owickstrom

  34. Exhaustiveness checking @owickstrom

  35. Simple interoperability with Go @owickstrom

  36. Fun! @owickstrom

  37. Open-source from the beginning @owickstrom

  38. Figure: MVP Pyramid @owickstrom

  39. Current State @owickstrom

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

  41. Operators !true - * / ( - ) / *

    -( ) ! "Foo" "Bar" false && (true || ( )) @owickstrom
  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
  43. No custom operators @owickstrom

  44. No macros @owickstrom

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

    twice(plus( )) forty plusTwenty( ) @owickstrom
  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
  47. Imports from Go package main import html main() { println(html.EscapeString("Simon

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

    println(html.EscapeString("Simon & Garfunkel")) // Simon & Garfunkel } @owickstrom
  49. Records sweden { official "Kingdom Of Sweden", population , capital

    "Stockholm" } usa { official "United States of America", population , capital "Washington D.C." } @owickstrom
  50. Record Types sweden : { official : string, population :

    int, capital : string } @owickstrom
  51. Records and Row Polymorphism fullName(person) person.firstName " " person.lastName @owickstrom

  52. Records and Row Polymorphism fullName : forall r. { firstName

    : string, lastName : string | r } - string @owickstrom
  53. Protocols Spoiler: Very similar to type classes @owickstrom

  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
  55. Protocols position { x , y } distance { x

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

    , y } target position distance @owickstrom
  57. Procotols are not simple @owickstrom

  58. That’s not all @owickstrom

  59. Finding more information @owickstrom

  60. oden-lang.org @owickstrom

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

  62. playground.oden-lang.org @owickstrom

  63. @odenlang @owickstrom

  64. What’s next? @owickstrom

  65. Thank you! @owickstrom