SlideShare a Scribd company logo
ELIXIR’S TYPE OF OPTIMISM
HOW YOU CAN BE A TYPE OPTIMIST WITH
DIALYZER AND TYPESPEC
INTRODUCTION
TYPE BASICS
▸ Fundamental types: integer, atom,
list, tuple, function
▸ Composite types: list of integers,
tuple with varied members
▸ System of types: use of fundamental
and composite types in functions,
variables and structs.
INTRODUCTION
ONE WAY TO THINK ABOUT A TYPE SYSTEM
▸ The function call structure is the wiring
▸ The types define the expected signal shapes going in and
out.
A type is a pattern, it defines
structure and can define legal
value ranges or enumerations.
INTRODUCTION
TYPE CHECKING
▸ Static type checking
▸ Enforced during compilation
▸ Everything has to be right, declared
▸ Dynamic type checking
▸ Defined by use
▸ Runtime evaluation of operations at the fundamental level
▸ Pattern matching
OH BOY
HOLY WAR OF TYPE TYPES
WHICH IS BETTER?
ELIXIR TYPESPEC
THE ELIXIR POSITION
▸ Dynamic typing
▸ Runtime enforcement of operations (“5” + 7)
▸ Pattern matching, guards on functions create some limits
▸ Testing can validate the intended use of a function
WHAT ABOUT TESTING
▸ Can test expected and unexpected inputs
▸ Exercise the code to validate type
handling
▸ Developers are optimistic testers
▸ Easy to have unexpected input conditions
▸ Doesn’t protect future code.
▸ Best at validating a function’s
transformation
ELIXIR TYPESPEC
ELIXIR TYPESPEC
THE SUPER POWER OF DIALYZER
▸ How is a function called by actual code?
▸ How does a function call other functions?
▸ Write signatures that are declarative
▸ Infer types up and down the call stack
▸ More exhaustive than what can be written as tests
▸ Your functions and structs are documented and validated
ELIXIR TYPESPEC
DOWNSIDE
▸ Not DRY
▸ Define a struct
▸ Define a @type
▸ Write a function
▸ Write a @spec
▸ dialyzer takes a little time to run, output can be cryptic
DIALYZER
DIALYZER READS ALL THE TYPES DECLARED
▸ Reads all the type specifications in the core modules,
dependencies
▸ This takes a while, but is cached, done once.
▸ aka PLT, persistent lookup table
▸ Reads all the types you’ve declared
LET’S DO IT
SET UP
ADD DIALYXIR TO MIX.EXS DEPS()
defmodule Talk.Mixfile do
use Mix.Project
. . .
defp deps do
[
{:dialyxir, "~> 0.4", only: [:dev], runtime: false},
]
end
end
$ mix deps.get
$ mix deps.compile
Then
SET UP
NEW MIX TASK
$ mix helpmix # Runs the default task (current: "mix run")
mix app.start # Starts all registered apps
mix app.tree # Prints the application tree
mix archive # Lists installed archives
mix archive.build # Archives this project into a .ez file
mix archive.install # Installs an archive locally
mix archive.uninstall # Uninstalls archives
mix clean # Deletes generated application files
mix cmd # Executes the given command
mix compile # Compiles source files
mix deps # Lists dependencies and their status
mix deps.clean # Deletes the given dependencies' files
mix deps.compile # Compiles dependencies
mix deps.get # Gets all out of date dependencies
mix deps.tree # Prints the dependency tree
mix deps.unlock # Unlocks the given dependencies
mix deps.update # Updates the given dependencies
mix dialyzer # Runs dialyzer with default or project-defined flags.
mix do # Executes the tasks separated by comma
mix escript # Lists installed escripts
mix escript.build # Builds an escript for the project
mix escript.install # Installs an escript locally
mix escript.uninstall # Uninstalls escripts
mix help # Prints help information for tasks
mix hex # Prints Hex help information
mix hex.build # Builds a new package version locally
mix hex.config # Reads, updates or deletes Hex config
mix hex.docs # Fetch or open documentation of a package
mix hex.info # Prints Hex information
mix hex.key # Manages Hex API key
mix hex.outdated # Shows outdated Hex deps for the current project
mix hex.owner # Manages Hex package ownership
mix hex.public_keys # Manages Hex public keys
mix hex.publish # Publishes a new package version
mix hex.retire # Retires a package version
mix hex.search # Searches for package names
mix hex.user # Registers or manages Hex user
mix loadconfig # Loads and persists the given configuration
mix local # Lists local tasks
mix local.hex # Installs Hex locally
mix local.phoenix # Updates Phoenix locally
mix local.public_keys # Manages public keys
mix local.rebar # Installs Rebar locally
mix new # Creates a new Elixir project
mix phoenix.new # Creates a new Phoenix v1.2.1 application
mix profile.fprof # Profiles the given file or expression with fprof
mix run # Runs the given file or expression
mix test # Runs a project's tests
mix xref # Performs cross reference checks
iex -S mix # Starts IEx and runs the default task
SET UP
FIRST RUN
flash:talk 03:32 525$ mix dialyzerChecking PLT...
[:compiler, :elixir, :kernel, :logger, :stdlib]
Finding suitable PLTs
Looking up modules in dialyxir_erlang-19.2_elixir-1.4.1_deps-dev.plt
Looking up modules in dialyxir_erlang-19.2_elixir-1.4.1.plt
Looking up modules in dialyxir_erlang-19.2.plt
Finding applications for dialyxir_erlang-19.2.plt
Finding modules for dialyxir_erlang-19.2.plt
Creating dialyxir_erlang-19.2.plt
Looking up modules in dialyxir_erlang-19.2.plt
Removing 3 modules from dialyxir_erlang-19.2.plt
Checking 11 modules in dialyxir_erlang-19.2.plt
Adding 149 modules to dialyxir_erlang-19.2.plt
Finding applications for dialyxir_erlang-19.2_elixir-1.4.1.plt
Finding modules for dialyxir_erlang-19.2_elixir-1.4.1.plt
Copying dialyxir_erlang-19.2.plt to dialyxir_erlang-19.2_elixir-1.4.1.plt
Looking up modules in dialyxir_erlang-19.2_elixir-1.4.1.plt
Checking 160 modules in dialyxir_erlang-19.2_elixir-1.4.1.plt
Adding 220 modules to dialyxir_erlang-19.2_elixir-1.4.1.plt
Finding applications for dialyxir_erlang-19.2_elixir-1.4.1_deps-dev.plt
Finding modules for dialyxir_erlang-19.2_elixir-1.4.1_deps-dev.plt
Copying dialyxir_erlang-19.2_elixir-1.4.1.plt to dialyxir_erlang-19.2_elixir-1.
4.1_deps-dev.plt
Looking up modules in dialyxir_erlang-19.2_elixir-1.4.1_deps-dev.plt
Checking 380 modules in dialyxir_erlang-19.2_elixir-1.4.1_deps-dev.plt
Adding 57 modules to dialyxir_erlang-19.2_elixir-1.4.1_deps-dev.plt
Starting Dialyzer
dialyzer --no_check_plt --fullpath --plt /Users/danj/Documents/elixir/typespec-
talk/talk/_build/dev/dialyxir_erlang-19.2_elixir-1.4.1_deps-dev.plt /Users/danj
/Documents/elixir/typespec-talk/talk/_build/dev/lib/talk/ebin
Proceeding with analysis... done in 0m1.38s
done (passed successfully)
flash:talk 03:38 526$
‣ mix dialyzer
‣ First run on an empty
project ~6min
CARDS
CARD EXAMPLE
defmodule Card do
def kind({_suit,value}) when is_number(value), do: :number
def kind({_suit,_value}), do: :face
def check_cards(card) do
IO.puts("kind(#{inspect(card)}) -> #{inspect(kind(card))}")
end
def main do
check_cards({:spades, :king})
check_cards({:rubies, 10})
end
end
CARDS
DIALYZER NORMAL RESULT
$ mix dialyzer
Checking PLT...
[:compiler, :elixir, :kernel, :logger, :stdlib]
PLT is up to date!
Starting Dialyzer
dialyzer --no_check_plt --fullpath --plt /Users/danj/Documents/elixir/typespec-
talk/talk/_build/dev/dialyxir_erlang-19.2_elixir-1.4.1_deps-dev.plt /Users/
danj/Documents/elixir/typespec-talk/talk/_build/dev/lib/talk/ebin
Proceeding with analysis... done in 0m1.61s
done (passed successfully)
CARDS
ADD TYPES AND A SPEC
1defmodule Card do
2
7
11
12 def check_cards(card) do
13 IO.puts("kind(#{inspect(card)}) -> #{inspect(kind(card))}")
14 end
15
16 def main do
17 check_cards({:spades, :king})
18 check_cards({:rubies, 10})
19 end
20end
3 @type suit :: ( :spade | :heart | :club | :diamond )
4 @type value :: ( 2..10 | :jack | :queen | :king | :ace )
5 @type card :: { suit, value }
6 @type card_kind :: { :number | :face }
8 @spec kind(card()) :: card_kind()
9 def kind({_suit,value}) when is_number(value), do: :number
10 def kind({_suit,_value}), do: :face
CARDS
Proceeding with analysis...
lib/card.ex:8: Invalid type specification for function
'Elixir.Card':kind/1. The success typing is ({_,_}) -> 'face' |
'number'
done in 0m1.72s
done (warnings were emitted)
8 @spec kind(card()) :: card_kind()
5 @type card :: { suit, value }
6 @type card_kind :: { :number | :face }
6 @type card_kind :: ( :number | :face )
oops
CARDS
Proceeding with analysis...
lib/card.ex:16: Function main/0 has no local return
lib/card.ex:17: The call
'Elixir.Card':check_cards({'spades','king'}) will never return
since it differs in the 1st argument from the success typing
arguments: ({'club','ace' | 'jack' | 'king' | 'queen' | 2 | 3 | 4
| 5 | 6 | 7 | 8 | 9 | 10} | {'diamond','ace' | 'jack' | 'king' |
'queen' | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10} | {'heart','ace' |
'jack' | 'king' | 'queen' | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10} |
{'spade','ace' | 'jack' | 'king' | 'queen' | 2 | 3 | 4 | 5 | 6 |
7 | 8 | 9 | 10})
lib/card.ex:18: The call 'Elixir.Card':check_cards({'rubies',10})
will never return since it differs in the 1st argument from the
success typing arguments: ({'club','ace' | 'jack' | 'king' |
'queen' | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10} | {'diamond','ace'
| 'jack' | 'king' | 'queen' | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10}
| {'heart','ace' | 'jack' | 'king' | 'queen' | 2 | 3 | 4 | 5 | 6
| 7 | 8 | 9 | 10} | {'spade','ace' | 'jack' | 'king' | 'queen' |
2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10})
done in 0m1.75s
done (warnings were emitted)
CARDS
17 check_cards({:spades, :king})
lib/card.ex:17: The call
'Elixir.Card':check_cards({'spades','king'})
will never return since it differs in the 1st argument
from the success typing arguments:
({'club','ace' | 'jack' | 'king' | 'queen' | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10}
| {'diamond','ace' | 'jack' | 'king' | 'queen' | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| {'heart','ace' | 'jack' | 'king' | 'queen' | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10
| {'spade','ace' | 'jack' | 'king' | 'queen' | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10
)
CARDS
1defmodule Card do
2
3 @type suit :: ( :spade | :heart | :club | :diamond )
4 @type value :: ( 2..10 | :jack | :queen | :king | :ace )
5 @type card :: { suit, value }
6 @type card_kind :: ( :number | :face )
7
8 @spec kind(card()) :: card_kind()
9 def kind({_suit,value}) when is_number(value), do: :number
10 def kind({_suit,_value}), do: :face
11
12 @spec check_cards(card()) :: any()
13 def check_cards(card) do
14 IO.puts("kind(#{inspect(card)}) -> #{inspect(kind(card))}")
15 end
16
17 def main do
18 check_cards({:spade, :king})
19 check_cards({:diamond, 10})
20 end
21end
CARDS
CARD EXAMPLE
defmodule Card do
def kind({_suit,value}) when is_number(value), do: :number
def kind({_suit,_value}), do: :face
def check_cards(card) do
IO.puts("kind(#{inspect(card)}) -> #{inspect(kind(card))}")
end
def main do
check_cards({:spades, :king})
check_cards({:rubies, 10})
end
end
STRUCT
TYPES AND STRUCT
1defmodule Card do
2 defstruct [:suit, :value]
3
4 @type suit :: ( :spade | :heart | :club | :diamond )
5 @type value :: ( 2..10 | :jack | :queen | :king | :ace )
6
7 @type t :: %Card{ suit: suit(), value: value()}
8
9 @type card_kind :: ( :number | :face )
10
11 @spec kind(Card.t) :: card_kind()
12 def kind(%Card{value: value} = card) when is_number(value),
do: :number
13 def kind(_card), do: :face
14end
ADDITIONAL
RESOURCES
ADDITIONAL RESOURCES
DOCUMENTATION
▸ http://learnyousomeerlang.com/dialyzer
▸ https://hexdocs.pm/elixir/typespecs.html
▸ https://hex.pm/packages/dialyxir
▸ http://user.it.uu.se/~kostis/Papers/succ_types.pdf
▸ Elixir Conf 2016 Jason Voegele Dialyzer talk
THANK YOU

More Related Content

What's hot

Forget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowForget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Kacper Gunia
 
ECMAScript2015
ECMAScript2015ECMAScript2015
ECMAScript2015qmmr
 
Symfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il clienteSymfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il cliente
Leonardo Proietti
 
Practical JavaScript Programming - Session 7/8
Practical JavaScript Programming - Session 7/8Practical JavaScript Programming - Session 7/8
Practical JavaScript Programming - Session 7/8
Wilson Su
 
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
James Titcumb
 
The IoC Hydra
The IoC HydraThe IoC Hydra
The IoC Hydra
Kacper Gunia
 
Clean code
Clean codeClean code
Clean code
ifnu bima
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
Jeff Carouth
 
The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016
Kacper Gunia
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
Sanketkumar Biswas
 
Ruby Topic Maps Tutorial (2007-10-10)
Ruby Topic Maps Tutorial (2007-10-10)Ruby Topic Maps Tutorial (2007-10-10)
Ruby Topic Maps Tutorial (2007-10-10)
Benjamin Bock
 
Zero to SOLID
Zero to SOLIDZero to SOLID
Zero to SOLID
Vic Metcalfe
 
Essentials and Impactful Features of ES6
Essentials and Impactful Features of ES6Essentials and Impactful Features of ES6
Essentials and Impactful Features of ES6
Riza Fahmi
 
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you needDutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Kacper Gunia
 
You code sucks, let's fix it
You code sucks, let's fix itYou code sucks, let's fix it
You code sucks, let's fix it
Rafael Dohms
 
Symfony2 - extending the console component
Symfony2 - extending the console componentSymfony2 - extending the console component
Symfony2 - extending the console component
Hugo Hamon
 
Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6
Visual Engineering
 
7 rules of simple and maintainable code
7 rules of simple and maintainable code7 rules of simple and maintainable code
7 rules of simple and maintainable code
Geshan Manandhar
 
Workshop 5: JavaScript testing
Workshop 5: JavaScript testingWorkshop 5: JavaScript testing
Workshop 5: JavaScript testing
Visual Engineering
 

What's hot (20)

Forget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowForget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers Cracow
 
ECMAScript2015
ECMAScript2015ECMAScript2015
ECMAScript2015
 
PerlScripting
PerlScriptingPerlScripting
PerlScripting
 
Symfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il clienteSymfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il cliente
 
Practical JavaScript Programming - Session 7/8
Practical JavaScript Programming - Session 7/8Practical JavaScript Programming - Session 7/8
Practical JavaScript Programming - Session 7/8
 
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
 
The IoC Hydra
The IoC HydraThe IoC Hydra
The IoC Hydra
 
Clean code
Clean codeClean code
Clean code
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
 
The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
 
Ruby Topic Maps Tutorial (2007-10-10)
Ruby Topic Maps Tutorial (2007-10-10)Ruby Topic Maps Tutorial (2007-10-10)
Ruby Topic Maps Tutorial (2007-10-10)
 
Zero to SOLID
Zero to SOLIDZero to SOLID
Zero to SOLID
 
Essentials and Impactful Features of ES6
Essentials and Impactful Features of ES6Essentials and Impactful Features of ES6
Essentials and Impactful Features of ES6
 
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you needDutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
 
You code sucks, let's fix it
You code sucks, let's fix itYou code sucks, let's fix it
You code sucks, let's fix it
 
Symfony2 - extending the console component
Symfony2 - extending the console componentSymfony2 - extending the console component
Symfony2 - extending the console component
 
Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6
 
7 rules of simple and maintainable code
7 rules of simple and maintainable code7 rules of simple and maintainable code
7 rules of simple and maintainable code
 
Workshop 5: JavaScript testing
Workshop 5: JavaScript testingWorkshop 5: JavaScript testing
Workshop 5: JavaScript testing
 

Viewers also liked

How Elixir helped us scale our Video User Profile Service for the Olympics
How Elixir helped us scale our Video User Profile Service for the OlympicsHow Elixir helped us scale our Video User Profile Service for the Olympics
How Elixir helped us scale our Video User Profile Service for the Olympics
Emerson Macedo
 
Elixir basics-2
Elixir basics-2Elixir basics-2
Elixir basics-2
Ruben Amortegui
 
Elixir – Peeking into Elixir's Processes, OTP and Supervisors
Elixir – Peeking into Elixir's Processes, OTP and SupervisorsElixir – Peeking into Elixir's Processes, OTP and Supervisors
Elixir – Peeking into Elixir's Processes, OTP and SupervisorsBenjamin Tan
 
Learn Elixir at Manchester Lambda Lounge
Learn Elixir at Manchester Lambda LoungeLearn Elixir at Manchester Lambda Lounge
Learn Elixir at Manchester Lambda Lounge
Chi-chi Ekweozor
 
Building a Network IP Camera using Erlang
Building a Network IP Camera using ErlangBuilding a Network IP Camera using Erlang
Building a Network IP Camera using Erlang
Frank Hunleth
 
ELIXIR Webinar: Introducing TeSS
ELIXIR Webinar: Introducing TeSSELIXIR Webinar: Introducing TeSS
ELIXIR Webinar: Introducing TeSS
Niall Beard
 
Spark as a distributed Scala
Spark as a distributed ScalaSpark as a distributed Scala
Spark as a distributed Scala
Alex Fruzenshtein
 
WEB MINING: PATTERN DISCOVERY ON THE WORLD WIDE WEB - 2011
WEB MINING: PATTERN DISCOVERY ON THE WORLD WIDE WEB - 2011WEB MINING: PATTERN DISCOVERY ON THE WORLD WIDE WEB - 2011
WEB MINING: PATTERN DISCOVERY ON THE WORLD WIDE WEB - 2011
Mustafa TURAN
 
나프다 웨비너 1604: Elixir와 함수형 프로그래밍을 이용한 웹 개발
나프다 웨비너 1604: Elixir와 함수형 프로그래밍을 이용한 웹 개발나프다 웨비너 1604: Elixir와 함수형 프로그래밍을 이용한 웹 개발
나프다 웨비너 1604: Elixir와 함수형 프로그래밍을 이용한 웹 개발
Changwook Park
 
Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Elixir Club
 
Control flow in_elixir
Control flow in_elixirControl flow in_elixir
Control flow in_elixir
Anna Neyzberg
 
Spring IO for startups
Spring IO for startupsSpring IO for startups
Spring IO for startups
Alex Fruzenshtein
 
Flowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
Flowex: Flow-Based Programming with Elixir GenStage - Anton MishchukFlowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
Flowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
Elixir Club
 
Phoenix: Inflame the Web - Alex Troush
Phoenix: Inflame the Web - Alex TroushPhoenix: Inflame the Web - Alex Troush
Phoenix: Inflame the Web - Alex Troush
Elixir Club
 
GenStage and Flow - Jose Valim
GenStage and Flow - Jose Valim GenStage and Flow - Jose Valim
GenStage and Flow - Jose Valim
Elixir Club
 
Distributed system in Elixir
Distributed system in ElixirDistributed system in Elixir
Distributed system in Elixir
Changwook Park
 
Elixir & Phoenix 推坑
Elixir & Phoenix 推坑Elixir & Phoenix 推坑
Elixir & Phoenix 推坑
Chao-Ju Huang
 
Proteome array - antibody based proteome arrays
Proteome array - antibody based proteome arrays Proteome array - antibody based proteome arrays
Proteome array - antibody based proteome arrays
saraswathi rajakumar
 

Viewers also liked (20)

How Elixir helped us scale our Video User Profile Service for the Olympics
How Elixir helped us scale our Video User Profile Service for the OlympicsHow Elixir helped us scale our Video User Profile Service for the Olympics
How Elixir helped us scale our Video User Profile Service for the Olympics
 
Elixir basics-2
Elixir basics-2Elixir basics-2
Elixir basics-2
 
Elixir – Peeking into Elixir's Processes, OTP and Supervisors
Elixir – Peeking into Elixir's Processes, OTP and SupervisorsElixir – Peeking into Elixir's Processes, OTP and Supervisors
Elixir – Peeking into Elixir's Processes, OTP and Supervisors
 
Learn Elixir at Manchester Lambda Lounge
Learn Elixir at Manchester Lambda LoungeLearn Elixir at Manchester Lambda Lounge
Learn Elixir at Manchester Lambda Lounge
 
Building a Network IP Camera using Erlang
Building a Network IP Camera using ErlangBuilding a Network IP Camera using Erlang
Building a Network IP Camera using Erlang
 
The Magic Of Elixir
The Magic Of ElixirThe Magic Of Elixir
The Magic Of Elixir
 
ELIXIR Webinar: Introducing TeSS
ELIXIR Webinar: Introducing TeSSELIXIR Webinar: Introducing TeSS
ELIXIR Webinar: Introducing TeSS
 
Spark as a distributed Scala
Spark as a distributed ScalaSpark as a distributed Scala
Spark as a distributed Scala
 
Big Data eBook
Big Data eBookBig Data eBook
Big Data eBook
 
WEB MINING: PATTERN DISCOVERY ON THE WORLD WIDE WEB - 2011
WEB MINING: PATTERN DISCOVERY ON THE WORLD WIDE WEB - 2011WEB MINING: PATTERN DISCOVERY ON THE WORLD WIDE WEB - 2011
WEB MINING: PATTERN DISCOVERY ON THE WORLD WIDE WEB - 2011
 
나프다 웨비너 1604: Elixir와 함수형 프로그래밍을 이용한 웹 개발
나프다 웨비너 1604: Elixir와 함수형 프로그래밍을 이용한 웹 개발나프다 웨비너 1604: Elixir와 함수형 프로그래밍을 이용한 웹 개발
나프다 웨비너 1604: Elixir와 함수형 프로그래밍을 이용한 웹 개발
 
Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
 
Control flow in_elixir
Control flow in_elixirControl flow in_elixir
Control flow in_elixir
 
Spring IO for startups
Spring IO for startupsSpring IO for startups
Spring IO for startups
 
Flowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
Flowex: Flow-Based Programming with Elixir GenStage - Anton MishchukFlowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
Flowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
 
Phoenix: Inflame the Web - Alex Troush
Phoenix: Inflame the Web - Alex TroushPhoenix: Inflame the Web - Alex Troush
Phoenix: Inflame the Web - Alex Troush
 
GenStage and Flow - Jose Valim
GenStage and Flow - Jose Valim GenStage and Flow - Jose Valim
GenStage and Flow - Jose Valim
 
Distributed system in Elixir
Distributed system in ElixirDistributed system in Elixir
Distributed system in Elixir
 
Elixir & Phoenix 推坑
Elixir & Phoenix 推坑Elixir & Phoenix 推坑
Elixir & Phoenix 推坑
 
Proteome array - antibody based proteome arrays
Proteome array - antibody based proteome arrays Proteome array - antibody based proteome arrays
Proteome array - antibody based proteome arrays
 

Similar to Elixir and Dialyzer, Types and Typespecs, using and understanding them

Introduction to Elixir
Introduction to ElixirIntroduction to Elixir
Introduction to Elixir
Diacode
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot Camp
Troy Miles
 
React Native One Day
React Native One DayReact Native One Day
React Native One Day
Troy Miles
 
Blocks by Lachs Cox
Blocks by Lachs CoxBlocks by Lachs Cox
Blocks by Lachs Cox
lachie
 
Intro to React
Intro to ReactIntro to React
Intro to React
Troy Miles
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN Stack
Troy Miles
 
RedisGears: Meir Shpilraien
RedisGears: Meir ShpilraienRedisGears: Meir Shpilraien
RedisGears: Meir Shpilraien
Redis Labs
 
RedisGears
RedisGearsRedisGears
RedisGears
MeirShpilraien
 
React Native Evening
React Native EveningReact Native Evening
React Native Evening
Troy Miles
 
Linux Shell Scripting Craftsmanship
Linux Shell Scripting CraftsmanshipLinux Shell Scripting Craftsmanship
Linux Shell Scripting Craftsmanship
bokonen
 
What’s new in .NET
What’s new in .NETWhat’s new in .NET
What’s new in .NET
Doommaker
 
RHCSA EX200 - Summary
RHCSA EX200 - SummaryRHCSA EX200 - Summary
RHCSA EX200 - Summary
Nugroho Gito
 
PE1 Module 4.ppt
PE1 Module 4.pptPE1 Module 4.ppt
PE1 Module 4.ppt
balewayalew
 
A tour on ruby and friends
A tour on ruby and friendsA tour on ruby and friends
A tour on ruby and friends旻琦 潘
 
Elixir in a nutshell - Fundamental Concepts
Elixir in a nutshell - Fundamental ConceptsElixir in a nutshell - Fundamental Concepts
Elixir in a nutshell - Fundamental Concepts
Héla Ben Khalfallah
 
The Ring programming language version 1.5.1 book - Part 78 of 180
The Ring programming language version 1.5.1 book - Part 78 of 180The Ring programming language version 1.5.1 book - Part 78 of 180
The Ring programming language version 1.5.1 book - Part 78 of 180
Mahmoud Samir Fayed
 
RubyEnRails2007 - Dr Nic Williams - DIY Syntax
RubyEnRails2007 - Dr Nic Williams - DIY SyntaxRubyEnRails2007 - Dr Nic Williams - DIY Syntax
RubyEnRails2007 - Dr Nic Williams - DIY Syntax
Dr Nic Williams
 
Compiler2016 by abcdabcd987
Compiler2016 by abcdabcd987Compiler2016 by abcdabcd987
Compiler2016 by abcdabcd987
乐群 陈
 
Wheels we didn't re-invent: Perl's Utility Modules
Wheels we didn't re-invent: Perl's Utility ModulesWheels we didn't re-invent: Perl's Utility Modules
Wheels we didn't re-invent: Perl's Utility Modules
Workhorse Computing
 

Similar to Elixir and Dialyzer, Types and Typespecs, using and understanding them (20)

Introduction to Elixir
Introduction to ElixirIntroduction to Elixir
Introduction to Elixir
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot Camp
 
React Native One Day
React Native One DayReact Native One Day
React Native One Day
 
Blocks by Lachs Cox
Blocks by Lachs CoxBlocks by Lachs Cox
Blocks by Lachs Cox
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN Stack
 
RedisGears: Meir Shpilraien
RedisGears: Meir ShpilraienRedisGears: Meir Shpilraien
RedisGears: Meir Shpilraien
 
RedisGears
RedisGearsRedisGears
RedisGears
 
Meta Object Protocols
Meta Object ProtocolsMeta Object Protocols
Meta Object Protocols
 
React Native Evening
React Native EveningReact Native Evening
React Native Evening
 
Linux Shell Scripting Craftsmanship
Linux Shell Scripting CraftsmanshipLinux Shell Scripting Craftsmanship
Linux Shell Scripting Craftsmanship
 
What’s new in .NET
What’s new in .NETWhat’s new in .NET
What’s new in .NET
 
RHCSA EX200 - Summary
RHCSA EX200 - SummaryRHCSA EX200 - Summary
RHCSA EX200 - Summary
 
PE1 Module 4.ppt
PE1 Module 4.pptPE1 Module 4.ppt
PE1 Module 4.ppt
 
A tour on ruby and friends
A tour on ruby and friendsA tour on ruby and friends
A tour on ruby and friends
 
Elixir in a nutshell - Fundamental Concepts
Elixir in a nutshell - Fundamental ConceptsElixir in a nutshell - Fundamental Concepts
Elixir in a nutshell - Fundamental Concepts
 
The Ring programming language version 1.5.1 book - Part 78 of 180
The Ring programming language version 1.5.1 book - Part 78 of 180The Ring programming language version 1.5.1 book - Part 78 of 180
The Ring programming language version 1.5.1 book - Part 78 of 180
 
RubyEnRails2007 - Dr Nic Williams - DIY Syntax
RubyEnRails2007 - Dr Nic Williams - DIY SyntaxRubyEnRails2007 - Dr Nic Williams - DIY Syntax
RubyEnRails2007 - Dr Nic Williams - DIY Syntax
 
Compiler2016 by abcdabcd987
Compiler2016 by abcdabcd987Compiler2016 by abcdabcd987
Compiler2016 by abcdabcd987
 
Wheels we didn't re-invent: Perl's Utility Modules
Wheels we didn't re-invent: Perl's Utility ModulesWheels we didn't re-invent: Perl's Utility Modules
Wheels we didn't re-invent: Perl's Utility Modules
 

Recently uploaded

AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
AI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website CreatorAI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website Creator
Google
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
Roshan Dwivedi
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 

Recently uploaded (20)

AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
AI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website CreatorAI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website Creator
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 

Elixir and Dialyzer, Types and Typespecs, using and understanding them

  • 1. ELIXIR’S TYPE OF OPTIMISM HOW YOU CAN BE A TYPE OPTIMIST WITH DIALYZER AND TYPESPEC
  • 2. INTRODUCTION TYPE BASICS ▸ Fundamental types: integer, atom, list, tuple, function ▸ Composite types: list of integers, tuple with varied members ▸ System of types: use of fundamental and composite types in functions, variables and structs.
  • 3. INTRODUCTION ONE WAY TO THINK ABOUT A TYPE SYSTEM ▸ The function call structure is the wiring ▸ The types define the expected signal shapes going in and out. A type is a pattern, it defines structure and can define legal value ranges or enumerations.
  • 4. INTRODUCTION TYPE CHECKING ▸ Static type checking ▸ Enforced during compilation ▸ Everything has to be right, declared ▸ Dynamic type checking ▸ Defined by use ▸ Runtime evaluation of operations at the fundamental level ▸ Pattern matching
  • 5. OH BOY HOLY WAR OF TYPE TYPES WHICH IS BETTER?
  • 6. ELIXIR TYPESPEC THE ELIXIR POSITION ▸ Dynamic typing ▸ Runtime enforcement of operations (“5” + 7) ▸ Pattern matching, guards on functions create some limits ▸ Testing can validate the intended use of a function
  • 7. WHAT ABOUT TESTING ▸ Can test expected and unexpected inputs ▸ Exercise the code to validate type handling ▸ Developers are optimistic testers ▸ Easy to have unexpected input conditions ▸ Doesn’t protect future code. ▸ Best at validating a function’s transformation ELIXIR TYPESPEC
  • 8. ELIXIR TYPESPEC THE SUPER POWER OF DIALYZER ▸ How is a function called by actual code? ▸ How does a function call other functions? ▸ Write signatures that are declarative ▸ Infer types up and down the call stack ▸ More exhaustive than what can be written as tests ▸ Your functions and structs are documented and validated
  • 9. ELIXIR TYPESPEC DOWNSIDE ▸ Not DRY ▸ Define a struct ▸ Define a @type ▸ Write a function ▸ Write a @spec ▸ dialyzer takes a little time to run, output can be cryptic
  • 10. DIALYZER DIALYZER READS ALL THE TYPES DECLARED ▸ Reads all the type specifications in the core modules, dependencies ▸ This takes a while, but is cached, done once. ▸ aka PLT, persistent lookup table ▸ Reads all the types you’ve declared
  • 12. SET UP ADD DIALYXIR TO MIX.EXS DEPS() defmodule Talk.Mixfile do use Mix.Project . . . defp deps do [ {:dialyxir, "~> 0.4", only: [:dev], runtime: false}, ] end end $ mix deps.get $ mix deps.compile Then
  • 13. SET UP NEW MIX TASK $ mix helpmix # Runs the default task (current: "mix run") mix app.start # Starts all registered apps mix app.tree # Prints the application tree mix archive # Lists installed archives mix archive.build # Archives this project into a .ez file mix archive.install # Installs an archive locally mix archive.uninstall # Uninstalls archives mix clean # Deletes generated application files mix cmd # Executes the given command mix compile # Compiles source files mix deps # Lists dependencies and their status mix deps.clean # Deletes the given dependencies' files mix deps.compile # Compiles dependencies mix deps.get # Gets all out of date dependencies mix deps.tree # Prints the dependency tree mix deps.unlock # Unlocks the given dependencies mix deps.update # Updates the given dependencies mix dialyzer # Runs dialyzer with default or project-defined flags. mix do # Executes the tasks separated by comma mix escript # Lists installed escripts mix escript.build # Builds an escript for the project mix escript.install # Installs an escript locally mix escript.uninstall # Uninstalls escripts mix help # Prints help information for tasks mix hex # Prints Hex help information mix hex.build # Builds a new package version locally mix hex.config # Reads, updates or deletes Hex config mix hex.docs # Fetch or open documentation of a package mix hex.info # Prints Hex information mix hex.key # Manages Hex API key mix hex.outdated # Shows outdated Hex deps for the current project mix hex.owner # Manages Hex package ownership mix hex.public_keys # Manages Hex public keys mix hex.publish # Publishes a new package version mix hex.retire # Retires a package version mix hex.search # Searches for package names mix hex.user # Registers or manages Hex user mix loadconfig # Loads and persists the given configuration mix local # Lists local tasks mix local.hex # Installs Hex locally mix local.phoenix # Updates Phoenix locally mix local.public_keys # Manages public keys mix local.rebar # Installs Rebar locally mix new # Creates a new Elixir project mix phoenix.new # Creates a new Phoenix v1.2.1 application mix profile.fprof # Profiles the given file or expression with fprof mix run # Runs the given file or expression mix test # Runs a project's tests mix xref # Performs cross reference checks iex -S mix # Starts IEx and runs the default task
  • 14. SET UP FIRST RUN flash:talk 03:32 525$ mix dialyzerChecking PLT... [:compiler, :elixir, :kernel, :logger, :stdlib] Finding suitable PLTs Looking up modules in dialyxir_erlang-19.2_elixir-1.4.1_deps-dev.plt Looking up modules in dialyxir_erlang-19.2_elixir-1.4.1.plt Looking up modules in dialyxir_erlang-19.2.plt Finding applications for dialyxir_erlang-19.2.plt Finding modules for dialyxir_erlang-19.2.plt Creating dialyxir_erlang-19.2.plt Looking up modules in dialyxir_erlang-19.2.plt Removing 3 modules from dialyxir_erlang-19.2.plt Checking 11 modules in dialyxir_erlang-19.2.plt Adding 149 modules to dialyxir_erlang-19.2.plt Finding applications for dialyxir_erlang-19.2_elixir-1.4.1.plt Finding modules for dialyxir_erlang-19.2_elixir-1.4.1.plt Copying dialyxir_erlang-19.2.plt to dialyxir_erlang-19.2_elixir-1.4.1.plt Looking up modules in dialyxir_erlang-19.2_elixir-1.4.1.plt Checking 160 modules in dialyxir_erlang-19.2_elixir-1.4.1.plt Adding 220 modules to dialyxir_erlang-19.2_elixir-1.4.1.plt Finding applications for dialyxir_erlang-19.2_elixir-1.4.1_deps-dev.plt Finding modules for dialyxir_erlang-19.2_elixir-1.4.1_deps-dev.plt Copying dialyxir_erlang-19.2_elixir-1.4.1.plt to dialyxir_erlang-19.2_elixir-1. 4.1_deps-dev.plt Looking up modules in dialyxir_erlang-19.2_elixir-1.4.1_deps-dev.plt Checking 380 modules in dialyxir_erlang-19.2_elixir-1.4.1_deps-dev.plt Adding 57 modules to dialyxir_erlang-19.2_elixir-1.4.1_deps-dev.plt Starting Dialyzer dialyzer --no_check_plt --fullpath --plt /Users/danj/Documents/elixir/typespec- talk/talk/_build/dev/dialyxir_erlang-19.2_elixir-1.4.1_deps-dev.plt /Users/danj /Documents/elixir/typespec-talk/talk/_build/dev/lib/talk/ebin Proceeding with analysis... done in 0m1.38s done (passed successfully) flash:talk 03:38 526$ ‣ mix dialyzer ‣ First run on an empty project ~6min
  • 15. CARDS CARD EXAMPLE defmodule Card do def kind({_suit,value}) when is_number(value), do: :number def kind({_suit,_value}), do: :face def check_cards(card) do IO.puts("kind(#{inspect(card)}) -> #{inspect(kind(card))}") end def main do check_cards({:spades, :king}) check_cards({:rubies, 10}) end end
  • 16. CARDS DIALYZER NORMAL RESULT $ mix dialyzer Checking PLT... [:compiler, :elixir, :kernel, :logger, :stdlib] PLT is up to date! Starting Dialyzer dialyzer --no_check_plt --fullpath --plt /Users/danj/Documents/elixir/typespec- talk/talk/_build/dev/dialyxir_erlang-19.2_elixir-1.4.1_deps-dev.plt /Users/ danj/Documents/elixir/typespec-talk/talk/_build/dev/lib/talk/ebin Proceeding with analysis... done in 0m1.61s done (passed successfully)
  • 17. CARDS ADD TYPES AND A SPEC 1defmodule Card do 2 7 11 12 def check_cards(card) do 13 IO.puts("kind(#{inspect(card)}) -> #{inspect(kind(card))}") 14 end 15 16 def main do 17 check_cards({:spades, :king}) 18 check_cards({:rubies, 10}) 19 end 20end 3 @type suit :: ( :spade | :heart | :club | :diamond ) 4 @type value :: ( 2..10 | :jack | :queen | :king | :ace ) 5 @type card :: { suit, value } 6 @type card_kind :: { :number | :face } 8 @spec kind(card()) :: card_kind() 9 def kind({_suit,value}) when is_number(value), do: :number 10 def kind({_suit,_value}), do: :face
  • 18. CARDS Proceeding with analysis... lib/card.ex:8: Invalid type specification for function 'Elixir.Card':kind/1. The success typing is ({_,_}) -> 'face' | 'number' done in 0m1.72s done (warnings were emitted) 8 @spec kind(card()) :: card_kind() 5 @type card :: { suit, value } 6 @type card_kind :: { :number | :face } 6 @type card_kind :: ( :number | :face ) oops
  • 19. CARDS Proceeding with analysis... lib/card.ex:16: Function main/0 has no local return lib/card.ex:17: The call 'Elixir.Card':check_cards({'spades','king'}) will never return since it differs in the 1st argument from the success typing arguments: ({'club','ace' | 'jack' | 'king' | 'queen' | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10} | {'diamond','ace' | 'jack' | 'king' | 'queen' | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10} | {'heart','ace' | 'jack' | 'king' | 'queen' | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10} | {'spade','ace' | 'jack' | 'king' | 'queen' | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10}) lib/card.ex:18: The call 'Elixir.Card':check_cards({'rubies',10}) will never return since it differs in the 1st argument from the success typing arguments: ({'club','ace' | 'jack' | 'king' | 'queen' | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10} | {'diamond','ace' | 'jack' | 'king' | 'queen' | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10} | {'heart','ace' | 'jack' | 'king' | 'queen' | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10} | {'spade','ace' | 'jack' | 'king' | 'queen' | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10}) done in 0m1.75s done (warnings were emitted)
  • 20. CARDS 17 check_cards({:spades, :king}) lib/card.ex:17: The call 'Elixir.Card':check_cards({'spades','king'}) will never return since it differs in the 1st argument from the success typing arguments: ({'club','ace' | 'jack' | 'king' | 'queen' | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10} | {'diamond','ace' | 'jack' | 'king' | 'queen' | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | | {'heart','ace' | 'jack' | 'king' | 'queen' | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | {'spade','ace' | 'jack' | 'king' | 'queen' | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 )
  • 21. CARDS 1defmodule Card do 2 3 @type suit :: ( :spade | :heart | :club | :diamond ) 4 @type value :: ( 2..10 | :jack | :queen | :king | :ace ) 5 @type card :: { suit, value } 6 @type card_kind :: ( :number | :face ) 7 8 @spec kind(card()) :: card_kind() 9 def kind({_suit,value}) when is_number(value), do: :number 10 def kind({_suit,_value}), do: :face 11 12 @spec check_cards(card()) :: any() 13 def check_cards(card) do 14 IO.puts("kind(#{inspect(card)}) -> #{inspect(kind(card))}") 15 end 16 17 def main do 18 check_cards({:spade, :king}) 19 check_cards({:diamond, 10}) 20 end 21end
  • 22. CARDS CARD EXAMPLE defmodule Card do def kind({_suit,value}) when is_number(value), do: :number def kind({_suit,_value}), do: :face def check_cards(card) do IO.puts("kind(#{inspect(card)}) -> #{inspect(kind(card))}") end def main do check_cards({:spades, :king}) check_cards({:rubies, 10}) end end
  • 23. STRUCT TYPES AND STRUCT 1defmodule Card do 2 defstruct [:suit, :value] 3 4 @type suit :: ( :spade | :heart | :club | :diamond ) 5 @type value :: ( 2..10 | :jack | :queen | :king | :ace ) 6 7 @type t :: %Card{ suit: suit(), value: value()} 8 9 @type card_kind :: ( :number | :face ) 10 11 @spec kind(Card.t) :: card_kind() 12 def kind(%Card{value: value} = card) when is_number(value), do: :number 13 def kind(_card), do: :face 14end
  • 25. ADDITIONAL RESOURCES DOCUMENTATION ▸ http://learnyousomeerlang.com/dialyzer ▸ https://hexdocs.pm/elixir/typespecs.html ▸ https://hex.pm/packages/dialyxir ▸ http://user.it.uu.se/~kostis/Papers/succ_types.pdf ▸ Elixir Conf 2016 Jason Voegele Dialyzer talk