Slide 1

Slide 1 text

Oden A Functional Programming Language for the Go Ecosystem Oskar Wickström (@owickstrom)

Slide 2

Slide 2 text

Agenda • Background • Project Goals • Current State • What’s next? • Questions

Slide 3

Slide 3 text

Background

Slide 4

Slide 4 text

Things I’ve been thinking about lately

Slide 5

Slide 5 text

I want type-safe functional programming for writing servers.

Slide 6

Slide 6 text

Haskell is a great language.

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

Do I really need interactive development? How much complexity does the REPL bring?

Slide 9

Slide 9 text

We should optimize for writing code that is correct, readable, and safe to change.

Slide 10

Slide 10 text

We should not optimize for cleverness.

Slide 11

Slide 11 text

Maybe static typing on top of Javascript?

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

Yes, we can!

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

What I’m missing in Go

Slide 17

Slide 17 text

Expressions over statements

Slide 18

Slide 18 text

Generic Programming

Slide 19

Slide 19 text

Abstraction

Slide 20

Slide 20 text

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 }

Slide 21

Slide 21 text

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 }

Slide 22

Slide 22 text

if err ! nil { return err }

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

Project Goals

Slide 25

Slide 25 text

Use Go as a platform

Slide 26

Slide 26 text

Avoid cleverness, prefer clarity

Slide 27

Slide 27 text

Expressions over statements

Slide 28

Slide 28 text

Support generic programming

Slide 29

Slide 29 text

Support good abstractions

Slide 30

Slide 30 text

Type inference

Slide 31

Slide 31 text

Immutability by default

Slide 32

Slide 32 text

Pattern matching

Slide 33

Slide 33 text

Exhaustiveness checking

Slide 34

Slide 34 text

Simple interoperability with Go

Slide 35

Slide 35 text

Fun!

Slide 36

Slide 36 text

Open-source from the beginning

Slide 37

Slide 37 text

Figure: MVP Pyramid

Slide 38

Slide 38 text

Current State

Slide 39

Slide 39 text

Hello World package main main() println("Hello World")

Slide 40

Slide 40 text

Operators - * / ( - ) / * ( ) ! "Foo" "Bar" false && (true || ( ))

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

No custom operators

Slide 43

Slide 43 text

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

Slide 44

Slide 44 text

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( )

Slide 45

Slide 45 text

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

Slide 46

Slide 46 text

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

Slide 47

Slide 47 text

Record Types sweden : { official : string, population : int, capital : string }

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

Protocols Spoiler: Very similar to type classes

Slide 51

Slide 51 text

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

Slide 52

Slide 52 text

Protocols position { x , y } distance { x , y } target Monoid::Apply(position, distance)

Slide 53

Slide 53 text

Protocols position { x , y } distance { x , y } target position distance

Slide 54

Slide 54 text

Finding more information

Slide 55

Slide 55 text

oden-lang.org

Slide 56

Slide 56 text

oden-lang.org/user-guide/latest/

Slide 57

Slide 57 text

playground.oden-lang.org

Slide 58

Slide 58 text

@odenlang

Slide 59

Slide 59 text

What’s next?

Slide 60

Slide 60 text

Thank you!