Slide 1

Slide 1 text

Augmenting Dynamic Typing with Static-Analysis Reid Draper @reiddraper

Slide 2

Slide 2 text

Reid Draper @reiddraper

Slide 3

Slide 3 text

takeaways

Slide 4

Slide 4 text

tl;dr

Slide 5

Slide 5 text

JUST USE HASKELL

Slide 6

Slide 6 text

JUST USE IDRIS

Slide 7

Slide 7 text

several modern functional languages have optional type systems

Slide 8

Slide 8 text

they are mature enough to be useful

Slide 9

Slide 9 text

they find real bugs

Slide 10

Slide 10 text

and improve documentation

Slide 11

Slide 11 text

with some work, you can integrate them into your CI system

Slide 12

Slide 12 text

motivation

Slide 13

Slide 13 text

%% Return a list of locators, in our case, we'll use cluster names %% that were saved in the ring cluster_mgr_sites_fun() -> %% get cluster names from cluster manager Ring = riak_core_ring_manager:get_my_ring(), Clusters = riak_repl_ring:get_clusters(Ring), [{?CLUSTER_NAME_LOCATOR_TYPE, Name} || {Name, _Addrs} <- Clusters].

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

static-typing has many benefits

Slide 16

Slide 16 text

prevents many errors during compile-time

Slide 17

Slide 17 text

enhanced documentation

Slide 18

Slide 18 text

%% @doc Return a list of all manifests in the %% `active' or `writing' state active_and_writing_manifests(Dict) -> orddict:to_list(filter_manifests_by_state(Dict, [active, writing])).

Slide 19

Slide 19 text

%% @doc Return a list of all manifests in the %% `active' or `writing' state -spec active_and_writing_manifests(orddict:orddict()) -> [{binary(), lfs_manifest()}]. active_and_writing_manifests(Dict) -> orddict:to_list(filter_manifests_by_state(Dict, [active, writing])).

Slide 20

Slide 20 text

-spec f(orddict:orddict()) -> [{binary(), lfs_manifest()}]. !

Slide 21

Slide 21 text

a guide for structuring programs

Slide 22

Slide 22 text

(potentially) better performance

Slide 23

Slide 23 text

there are many popular dynamically-typed languages in industry

Slide 24

Slide 24 text

JavaScript Java PHP C# Python! C++ Ruby C Objective-C CSS Perl Shell Scala Haskell R Matlab Clojure CoffeeScript Visual Basic Groovy http://redmonk.com/sogrady/2014/01/22/language-rankings-1-14/

Slide 25

Slide 25 text

so what do we do?

Slide 26

Slide 26 text

can we add a type-system?

Slide 27

Slide 27 text

Retrofitting a type system into a language not designed with typechecking in mind can be tricky; ideally, language design should go hand-in-hand with type system design. Benjamin C. Pierce, Types and Programming Languages p. 9

Slide 28

Slide 28 text

history

Slide 29

Slide 29 text

an incomplete and likely wrong history

Slide 30

Slide 30 text

adding dynamic types to a statically-typed language 1989 M. Abadi, L. Cardelli, B. Pierce, G. Plotkin, statically-typed language

Slide 31

Slide 31 text

Cartwright and Fagan introduce Soft-Typing 1991 Robert Cartwright, Mike Fagan,

Slide 32

Slide 32 text

"The key concept of soft typing is that a type checker need not reject programs containing statically 'ill typed' phrases" 1991 Robert Cartwright, Mike Fagan,

Slide 33

Slide 33 text

Soft-Types implemented with Scheme 1994 Andrew K. Wright , Robert Cartwright,

Slide 34

Slide 34 text

Marlow and Wadler add static- types to Erlang* 1997 * with some caveats… Andrew K. Wright , Robert Cartwright,

Slide 35

Slide 35 text

Bracha introduces optional types in Pluggable Type Systems 2004 Gilad Bracha,

Slide 36

Slide 36 text

"In contrast, optional type systems are neither syntactically nor semantically required, and have no effect on the dynamic semantics of the language." 2004 Gilad Bracha,

Slide 37

Slide 37 text

Erlang's Dialyzer becomes viable 2006 Lindahl, Sagonas,

Slide 38

Slide 38 text

overcomes many of the issues Marlow and Wadler had 2004 Lindahl, Sagonas,

Slide 39

Slide 39 text

Gradual typing for functional languages 2006 Siek, Taha,

Slide 40

Slide 40 text

The design and implementation of typed scheme 2008 now called Typed Racket Tobin-Hochstadt, Felleisen,

Slide 41

Slide 41 text

inspiration for typed Clojure 2008 Tobin-Hochstadt, Felleisen,

Slide 42

Slide 42 text

introduces Occurrence typing 2008 Tobin-Hochstadt, Felleisen,

Slide 43

Slide 43 text

(: flexible-length (-> (U String (Listof Any)) Integer)) (define (flexible-length str-or-lst) (if (string? str-or-lst) (string-length str-or-lst) (length str-or-lst)))

Slide 44

Slide 44 text

state of the art

Slide 45

Slide 45 text

Dialyzer for Erlang

Slide 46

Slide 46 text

Typed Racket

Slide 47

Slide 47 text

Typed Clojure

Slide 48

Slide 48 text

Dart

Slide 49

Slide 49 text

Dialyzer at Basho

Slide 50

Slide 50 text

we write a distributed database in Erlang: Riak

Slide 51

Slide 51 text

correctness and fault-tolerance are import

Slide 52

Slide 52 text

bugs are inevitable

Slide 53

Slide 53 text

sometimes embarrassing

Slide 54

Slide 54 text

avoid preventable bugs

Slide 55

Slide 55 text

we use Dialyzer for this

Slide 56

Slide 56 text

recently hooked it up with CI

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

takeaways

Slide 69

Slide 69 text

tl;dr

Slide 70

Slide 70 text

several modern functional languages have optional type systems

Slide 71

Slide 71 text

they are mature enough to be useful

Slide 72

Slide 72 text

they find real bugs

Slide 73

Slide 73 text

and improve documentation

Slide 74

Slide 74 text

with some work, you can integrate them into your CI system

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

Questions? @reiddraper