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 useful
they find real bugs
and improve documentation
with some work, you can integrate them into your CI system
motivation
%% 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) -> orddict:to_list(filter_manifests_by_state(Dict, [active, writing])).
%% @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])).
-spec f(orddict:orddict()) -> [{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
history
an incomplete and likely wrong history
1989 adding dynamic types to a statically-typed language M. Abadi, L. Cardelli, B. Pierce, G. Plotkin, statically-typed language
1991 Cartwright and Fagan introduce Soft-Typing Robert Cartwright, Mike Fagan,
1991 "The key concept of soft typing is that a type checker need not reject programs containing statically 'ill typed' phrases" Robert Cartwright, Mike Fagan,
1994 Soft-Types implemented with Scheme Andrew K. Wright , Robert Cartwright,
1997 Marlow and Wadler add static- types to Erlang* * with some caveats… Andrew K. Wright , Robert Cartwright,
2004 Bracha introduces optional types in Pluggable Type Systems Gilad Bracha,
2004 "In contrast, optional type systems are neither syntactically nor semantically required, and have no effect on the dynamic semantics of the language." Gilad Bracha,
2006 Erlang's Dialyzer becomes viable Lindahl, Sagonas,
2004 overcomes many of the issues Marlow and Wadler had Lindahl, Sagonas,
2006 Gradual typing for functional languages Siek, Taha,
2008 The design and implementation of typed scheme now called Typed Racket Tobin-Hochstadt, Felleisen,
2008 inspiration for typed Clojure Tobin-Hochstadt, Felleisen,
2008 introduces Occurrence typing 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)))
state of the art
Dialyzer for Erlang
Typed Racket
Typed Clojure
Dart
Dialyzer at Basho
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
takeaways
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
Questions? @reiddraper
Recommend
More recommend