Augmenting Dynamic Typing with Static-Analysis
Reid Draper @reiddraper
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
Augmenting Dynamic Typing with Static-Analysis
Reid Draper @reiddraper
@reiddraper
tl;dr
several modern functional languages have optional type systems
they are mature enough to be useful
they find real bugs
and improve documentation
with some work, you can integrate them into your CI system
%% 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].
static-typing has many benefits
prevents many errors during compile-time
enhanced documentation
%% @doc Return a list of all manifests in the %% `active' or `writing' state active_and_writing_manifests(Dict) ->
[active, writing])).
%% @doc Return a list of all manifests in the %% `active' or `writing' state
[{binary(), lfs_manifest()}]. active_and_writing_manifests(Dict) ->
[active, writing])).
[{binary(), lfs_manifest()}].
a guide for structuring programs
(potentially) better performance
there are many popular dynamically-typed languages in industry
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/
so what do we do?
can we add a type-system?
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
an incomplete and likely wrong history
adding dynamic types to a statically-typed language
1989
statically-typed language
Cartwright and Fagan introduce Soft-Typing
1991
Robert Cartwright, Mike Fagan,
"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,
Soft-Types implemented with Scheme
1994
Andrew K. Wright , Robert Cartwright,
Marlow and Wadler add static- types to Erlang*
1997
* with some caveats… Andrew K. Wright , Robert Cartwright,
Bracha introduces optional types in Pluggable Type Systems
2004
Gilad Bracha,
"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,
Erlang's Dialyzer becomes viable
2006
Lindahl, Sagonas,
Marlow and Wadler had
2004
Lindahl, Sagonas,
Gradual typing for functional languages
2006
Siek, Taha,
The design and implementation
2008
now called Typed Racket Tobin-Hochstadt, Felleisen,
inspiration for typed Clojure
2008
Tobin-Hochstadt, Felleisen,
introduces Occurrence typing
2008
Tobin-Hochstadt, Felleisen,
(: 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)))
Dialyzer for Erlang
Typed Racket
Typed Clojure
Dart
we write a distributed database in Erlang: Riak
correctness and fault-tolerance are import
bugs are inevitable
sometimes embarrassing
avoid preventable bugs
we use Dialyzer for this
recently hooked it up with CI
tl;dr
several modern functional languages have optional type systems
they are mature enough to be useful
they find real bugs
and improve documentation
with some work, you can integrate them into your CI system
@reiddraper