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. 3.

    Agenda • Background • Project Goals • Current State •

    What’s next? • Questions @owickstrom
  2. 8.

    Can we have the safety of Haskell, but in a

    smaller and simpler language? @owickstrom
  3. 13.

    Having to write FFI bindings to use libraries is cumbersome.

    Can the compiler do this for us? @owickstrom
  4. 14.

    Can we reuse all the good stuff from Go, but

    use a functional language? @owickstrom
  5. 16.

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

    channels • Cross-compilation • Static linking • Simple compile target • Fast compiler @owickstrom
  6. 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
  7. 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
  8. 24.

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

    return err } io.Copy(f, res.Body) if err ! nil { return err } return nil } @owickstrom
  9. 41.

    Operators !true - * / ( - ) / *

    -( ) ! "Foo" "Bar" false && (true || ( )) @owickstrom
  10. 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
  11. 45.

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

    twice(plus( )) forty plusTwenty( ) @owickstrom
  12. 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
  13. 47.

    Imports from Go package main import html main() { println(html.EscapeString("Simon

    & Garfunkel")) // Simon & Garfunkel } @owickstrom
  14. 48.

    Imports from Go package main import foreign "html" main() {

    println(html.EscapeString("Simon & Garfunkel")) // Simon & Garfunkel } @owickstrom
  15. 49.

    Records sweden { official "Kingdom Of Sweden", population , capital

    "Stockholm" } usa { official "United States of America", population , capital "Washington D.C." } @owickstrom
  16. 50.

    Record Types sweden : { official : string, population :

    int, capital : string } @owickstrom
  17. 52.

    Records and Row Polymorphism fullName : forall r. { firstName

    : string, lastName : string | r } - string @owickstrom
  18. 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
  19. 55.

    Protocols position { x , y } distance { x

    , y } target Monoid::Apply(position, distance) @owickstrom
  20. 56.

    Protocols position { x , y } distance { x

    , y } target position distance @owickstrom