48
The Next Gr ea t F unctional Programming Language (OK, no t r eally.) John A . De Goes — @jdegoes

The Next Great Functional Programming Language

Embed Size (px)

Citation preview

Page 1: The Next Great Functional Programming Language

The Next Great Functional Programming Language

(OK, not really.)

John A. De Goes — @jdegoes

Page 2: The Next Great Functional Programming Language

ML - 1973

Haskell - 19901

OCaml - 19962

2 Or 1987 if you count Caml.

1 Or 1985 if you count Miranda.

Page 3: The Next Great Functional Programming Language

Haskell

Page 4: The Next Great Functional Programming Language

Haskellz144 quadrillion flavors.

!

Page 5: The Next Great Functional Programming Language

Our Best FPLs Suffer from Decades Worth of

Accretion

Page 6: The Next Great Functional Programming Language

Individual Features were Designed, but the FPLs

Came Into Existence

Page 7: The Next Great Functional Programming Language

What Would a Designed FPL Look Like Today?

Page 8: The Next Great Functional Programming Language

?

Page 9: The Next Great Functional Programming Language

!

Page 10: The Next Great Functional Programming Language

[This Slide Intentionally Left Blank]

Page 11: The Next Great Functional Programming Language

My Ideal FPL4 Pattern Matching

4 Records

4 Modules

4 Syntax

4 Type Classes

4 Nominative Typing

4 Data

4 Recursion

Page 12: The Next Great Functional Programming Language

! Pattern Matching

Page 13: The Next Great Functional Programming Language

Pattern Matching import Lens.Family.Total import Lens.Family.Stock

total :: Either Char Int -> String -- Same as: total = _case -- total = \case & on _Left (\c -> replicate 3 c ) -- Left c -> replicate 3 c & on _Right (\n -> replicate n '!') -- Right n -> replicate n '!'

Page 14: The Next Great Functional Programming Language

! Records

Page 15: The Next Great Functional Programming Language

Recordsval book = ("author" ->> "Benjamin Pierce") :: ("title" ->> "Types and Programming Languages") :: ("id" ->> 262162091) :: ("price" ->> 44.11) :: HNil

scala> book("author") // Note result type ...res0: String = Benjamin Pierce

scala> val extended = book + ("inPrint" ->> true) // Add a new fieldextended: ... complex type elided ... = Benjamin Pierce :: Types and Programming Languages :: 262162091 :: 46.11 :: true :: HNil

scala> val noId = extended - "id" // Removed a fieldnoId: ... complex type elided ... = Benjamin Pierce :: Types and Programming Languages :: 46.11 :: true :: HNil

Page 16: The Next Great Functional Programming Language

! Modules

Page 17: The Next Great Functional Programming Language

Modulesstructure ListStack :> STACK =struct type t = 'a list [...]end

Page 18: The Next Great Functional Programming Language

Modulesdata Stack f = Stack { makeNew :: forall a. f a, push :: forall a. a -> f a -> f a, pop :: forall a. f a -> Maybe (Tuple a (f a)) }

doSomeStackStuff :: forall f. Stack f -> Thing

Page 19: The Next Great Functional Programming Language

Modulesdata Stack f = Stack { makeNew :: forall a. f a, push :: forall a. a -> f a -> f a, pop :: forall a. f a -> Maybe (Tuple a (f a)) }

data ReservationSystem f = ReservationSystem (forall g. Stack g -> { ... })

Page 20: The Next Great Functional Programming Language

! Syntax

Page 21: The Next Great Functional Programming Language

SyntaxLet's stop pretending programs are strings of ASCII characters.

4 implicits

4 order of function parameters / application

4 compiler errors

4 funky looking operators

4 scopes

4 Haskell-style (fake) modules & imports

4 name clashes

4 information elision

4 ...

Page 22: The Next Great Functional Programming Language

! Type Classes

Page 23: The Next Great Functional Programming Language

Type ClassesJust 'records' with compiler-enforced laws.3

3 Type classes also add an implicitly applied (a : Type) -> TypeClass a function that's piecewise-defined, but that's just syntax.

Page 24: The Next Great Functional Programming Language

! Partiality

Page 25: The Next Great Functional Programming Language

PartialityIf it's partial, it's not a &^@#% function.

Page 26: The Next Great Functional Programming Language

! Nominative Typing

Page 27: The Next Great Functional Programming Language

Nominative Typingdata Email = Email String

data DOMId = DOMId String

data Positive = Positive Float

data Negative = Negative Float

data DressSize = DressSize Float

Page 28: The Next Great Functional Programming Language

Nominative Typingdata ??? = ??? String

data ??? = ??? String

data ??? = ??? Float

data ??? = ??? Float

data ??? = ??? Float

Page 29: The Next Great Functional Programming Language

Let's Stop Pretending Differences in Names Actually Matter

Page 30: The Next Great Functional Programming Language

Nominative TypingLet's play a guessing game.

data ??? = ??? -- {v: Float | v > 0}

data ??? = ??? -- {v: Float | v < 0}

Page 31: The Next Great Functional Programming Language

! Data

Page 32: The Next Great Functional Programming Language

DataData: Bits-based description.

data Either a b = Left a | Right b

struct either { int tag; union { void *left; void *right; };};

Page 33: The Next Great Functional Programming Language

DataNewbies: addicted to pattern matching.

data List a = Nil | Cons a (List a)

doSomething :: forall a. List a -> IntdoSomething Nil = 0doSomething (Cons _ l) = 1 + doSomething l

Page 34: The Next Great Functional Programming Language

DataPros: addicted to folds.

fold :: forall z a. z -> (z -> a -> z) -> List a -> zfold z _ Nil = zfold z f (Cons a l) = fold (f z a) l

Page 35: The Next Great Functional Programming Language

DataFolds: Capability-based description.

fold :: forall z a. z -> (z -> a -> z) -> List a -> z

data List a = List (forall z. z -> (z -> a -> z) -> z)

Page 36: The Next Great Functional Programming Language

Datadata List a = List (forall z. z -> (z -> a -> z) -> z)

nil = \z f -> zcons a (List as) = \z f -> as (f a z) f

Array? Linked List? Vector? Skip List?4

4 Strictly more powerful than a data List (pros & cons).

Page 37: The Next Great Functional Programming Language

! Recursion

Page 38: The Next Great Functional Programming Language

RecursionGoto of functional programming.5

f x = if x / 2 > x then g (2 * x) else 42g x = if x % 1 == 0 then f (g (x + 1)) else h (x - 1)h x = if x % 1 == 1 then f (x * 2 + 1) else g (x + 1)

5 What's hard for a machine|human to understand is also hard for a human|machine to understand.

Page 39: The Next Great Functional Programming Language

RecursionInduction -> Folds.

Page 40: The Next Great Functional Programming Language

RecursionCoinduction -> State Machines.

type Machine s a b = (s, (s, a) -> (s, b))

6

6 Except this is too weakly typed.

Page 41: The Next Great Functional Programming Language

My Ideal FPL

Page 42: The Next Great Functional Programming Language

My Ideal FPLLayered like an onion.

4 Turing incomplete for 99% of program

4 Prove / optimize more

4 Turing complete 'driver'

4 Prove / optimize less

4 Possibly in a different language (e.g. Haskell)

Page 43: The Next Great Functional Programming Language

My Ideal FPLStructured editor.

4 Friendly FP

4 Destroys motivation for most language 'features'

Page 44: The Next Great Functional Programming Language

My Ideal FPLAll the things are values.

4 Math functions

4 Abolish incidental complexity

4 Abolish artificial distinctions

Page 45: The Next Great Functional Programming Language

My Ideal FPLProof search.

4 Turing complete

4 Levels of proof

1. Proven true

2. Evidence for truth but not proven true

3. Proven false (in general or by counterexample)

4 Massive, persistent proof databases

4 Cross-disciplinary research

4 e.g. deep learning to accelerate proof search

Page 46: The Next Great Functional Programming Language

My Ideal FPLZero cost abstraction.

4 As long as we're shooting for the moon

4 (But genuinely easier w/o recursion/data)

Page 47: The Next Great Functional Programming Language

Inspirations4 Unison Programming Language7

4 LiquidHaskell8

4 Morte9

9 http://www.haskellforall.com/2014/09/morte-intermediate-language-for-super.html

8 http://goto.ucsd.edu/~rjhala/liquid/haskell/blog/

7 http://unisonweb.org

Page 48: The Next Great Functional Programming Language

THANK YOUJohn A. De Goes — @jdegoes