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. Agenda • Background • Project Goals • Current State •

    What’s next? • Questions @owickstrom
  2. Can we have the safety of Haskell, but in a

    smaller and simpler language? @owickstrom
  3. Having to write FFI bindings to use libraries is cumbersome.

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

    use a functional language? @owickstrom
  5. Why Go? • Ecosystem of libraries and tools • Goroutines,

    channels • Cross-compilation • Static linking • Simple compile target • Fast compiler @owickstrom
  6. 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. 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. ... f, err : os.Create(localTarget) if err ! nil {

    return err } io.Copy(f, res.Body) if err ! nil { return err } return nil } @owickstrom
  9. Operators !true - * / ( - ) / *

    -( ) ! "Foo" "Bar" false && (true || ( )) @owickstrom
  10. 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. Curried Functions plus(x, y) x y twice(f, x) f(f(x)) plusTwenty

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

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

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

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

    int, capital : string } @owickstrom
  17. Records and Row Polymorphism fullName : forall r. { firstName

    : string, lastName : string | r } - string @owickstrom
  18. 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. Protocols position { x , y } distance { x

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

    , y } target position distance @owickstrom