Augmenting Dynamic Typing with Static-Analysis Reid Draper - - PowerPoint PPT Presentation

augmenting dynamic typing with static analysis
SMART_READER_LITE
LIVE PREVIEW

Augmenting Dynamic Typing with Static-Analysis Reid Draper - - PowerPoint PPT Presentation

Augmenting Dynamic Typing with Static-Analysis Reid Draper @reiddraper Reid Draper @reiddraper takeaways tl;dr JUST USE HASKELL JUST USE IDRIS several modern functional languages have optional type systems they are mature enough to be


slide-1
SLIDE 1

Augmenting Dynamic Typing with Static-Analysis

Reid Draper @reiddraper

slide-2
SLIDE 2

Reid Draper

@reiddraper

slide-3
SLIDE 3

takeaways

slide-4
SLIDE 4

tl;dr

slide-5
SLIDE 5

JUST USE HASKELL

slide-6
SLIDE 6

JUST USE IDRIS

slide-7
SLIDE 7

several modern functional languages have optional type systems

slide-8
SLIDE 8

they are mature enough to be useful

slide-9
SLIDE 9

they find real bugs

slide-10
SLIDE 10

and improve documentation

slide-11
SLIDE 11

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

slide-12
SLIDE 12

motivation

slide-13
SLIDE 13

%% 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
slide-15
SLIDE 15

static-typing has many benefits

slide-16
SLIDE 16

prevents many errors during compile-time

slide-17
SLIDE 17

enhanced documentation

slide-18
SLIDE 18

%% @doc Return a list of all manifests in the %% `active' or `writing' state active_and_writing_manifests(Dict) ->

  • rddict:to_list(filter_manifests_by_state(Dict,

[active, writing])).

slide-19
SLIDE 19

%% @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) ->

  • rddict:to_list(filter_manifests_by_state(Dict,

[active, writing])).

slide-20
SLIDE 20
  • spec f(orddict:orddict()) ->

[{binary(), lfs_manifest()}].

slide-21
SLIDE 21

a guide for structuring programs

slide-22
SLIDE 22

(potentially) better performance

slide-23
SLIDE 23

there are many popular dynamically-typed languages in industry

slide-24
SLIDE 24

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

so what do we do?

slide-26
SLIDE 26

can we add a type-system?

slide-27
SLIDE 27

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

history

slide-29
SLIDE 29

an incomplete and likely wrong history

slide-30
SLIDE 30

adding dynamic types to a statically-typed language

1989

  • M. Abadi, L. Cardelli, B. Pierce, G. Plotkin,

statically-typed language

slide-31
SLIDE 31

Cartwright and Fagan introduce Soft-Typing

1991

Robert Cartwright, Mike Fagan,

slide-32
SLIDE 32

"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

Soft-Types implemented with Scheme

1994

Andrew K. Wright , Robert Cartwright,

slide-34
SLIDE 34

Marlow and Wadler add static- types to Erlang*

1997

* with some caveats… Andrew K. Wright , Robert Cartwright,

slide-35
SLIDE 35

Bracha introduces optional types in Pluggable Type Systems

2004

Gilad Bracha,

slide-36
SLIDE 36

"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

Erlang's Dialyzer becomes viable

2006

Lindahl, Sagonas,

slide-38
SLIDE 38
  • vercomes many of the issues

Marlow and Wadler had

2004

Lindahl, Sagonas,

slide-39
SLIDE 39

Gradual typing for functional languages

2006

Siek, Taha,

slide-40
SLIDE 40

The design and implementation

  • f typed scheme

2008

now called Typed Racket Tobin-Hochstadt, Felleisen,

slide-41
SLIDE 41

inspiration for typed Clojure

2008

Tobin-Hochstadt, Felleisen,

slide-42
SLIDE 42

introduces Occurrence typing

2008

Tobin-Hochstadt, Felleisen,

slide-43
SLIDE 43

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

state of the art

slide-45
SLIDE 45

Dialyzer for Erlang

slide-46
SLIDE 46

Typed Racket

slide-47
SLIDE 47

Typed Clojure

slide-48
SLIDE 48

Dart

slide-49
SLIDE 49

Dialyzer at Basho

slide-50
SLIDE 50

we write a distributed database in Erlang: Riak

slide-51
SLIDE 51

correctness and fault-tolerance are import

slide-52
SLIDE 52

bugs are inevitable

slide-53
SLIDE 53

sometimes embarrassing

slide-54
SLIDE 54

avoid preventable bugs

slide-55
SLIDE 55

we use Dialyzer for this

slide-56
SLIDE 56

recently hooked it up with CI

slide-57
SLIDE 57
slide-58
SLIDE 58
slide-59
SLIDE 59
slide-60
SLIDE 60
slide-61
SLIDE 61
slide-62
SLIDE 62
slide-63
SLIDE 63
slide-64
SLIDE 64
slide-65
SLIDE 65
slide-66
SLIDE 66
slide-67
SLIDE 67
slide-68
SLIDE 68

takeaways

slide-69
SLIDE 69

tl;dr

slide-70
SLIDE 70

several modern functional languages have optional type systems

slide-71
SLIDE 71

they are mature enough to be useful

slide-72
SLIDE 72

they find real bugs

slide-73
SLIDE 73

and improve documentation

slide-74
SLIDE 74

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

slide-75
SLIDE 75
slide-76
SLIDE 76

Questions?

@reiddraper