SlideShare une entreprise Scribd logo
1  sur  29
Télécharger pour lire hors ligne
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Optional Type Specification in Erlang
Andreas Pauley – @apauley
Lambda Luminaries – @lambdaluminary

November 11, 2013

Andreas Pauley – @apauley

Types in Erlang
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Table of Contents
1

Erlang Type Overview

2

Can we add compile-time types to Erlang?

3

Optional Types

4

Dialyzer

5

Proper

6

Conclusion

Andreas Pauley – @apauley

Types in Erlang
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Dynamic, but strong

example({}) ->
"empty tuple";
example(List) when is_list(List) ->
length(List);
example(_Else) ->
another_return_type.

Andreas Pauley – @apauley

Types in Erlang
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Dynamic, but strong

3> 5 + "6".
** exception error: an error occurred when evaluating
an arithmetic expression
in operator +/2
called as 5 + "6"

Andreas Pauley – @apauley

Types in Erlang
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Table of Contents
1

Erlang Type Overview

2

Can we add compile-time types to Erlang?

3

Optional Types

4

Dialyzer

5

Proper

6

Conclusion

Andreas Pauley – @apauley

Types in Erlang
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Yes and No :-/

The Haskell giants Simon Marlow and Philip Wadler spent
over a year developing a static type system for Erlang (circa
1997).

Andreas Pauley – @apauley

Types in Erlang
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Yes and No :-/

The Haskell giants Simon Marlow and Philip Wadler spent
over a year developing a static type system for Erlang (circa
1997).
Only a subset of the language could be type-checked.

Andreas Pauley – @apauley

Types in Erlang
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Yes and No :-/

The Haskell giants Simon Marlow and Philip Wadler spent
over a year developing a static type system for Erlang (circa
1997).
Only a subset of the language could be type-checked.
Process types and inter-process messages could not be
type-checked.

Andreas Pauley – @apauley

Types in Erlang
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Table of Contents
1

Erlang Type Overview

2

Can we add compile-time types to Erlang?

3

Optional Types

4

Dialyzer

5

Proper

6

Conclusion

Andreas Pauley – @apauley

Types in Erlang
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Declaring Types

We can declare union/sum types and product types:
-type suit() :: spades | clubs | hearts | diamonds.
-type value() :: 1..10 | jack | queen | king.
-type card() :: {suit(), value()}.

Andreas Pauley – @apauley

Types in Erlang
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Declaring Types

Types in record definitions:
-record(rsa_id_number, {birth_date
gender_digit
sequence_nr
citizen_digit
digit_a
checksum_digit

Andreas Pauley – @apauley

Types in Erlang

::
::
::
::
::
::

calendar:date(),
0..9,
0..999,
0 | 1,
0..9,
0..9}).
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Using Types

-spec suit(card()) -> suit().
suit({Suit, _}) -> Suit.

Andreas Pauley – @apauley

Types in Erlang
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Using Types

-type gender() :: male | female.
-type rsa_id_number() :: #rsa_id_number{}.
-export_type([rsa_id_number/0]).
-spec gender(rsa_id_number()) -> gender().
gender(#rsa_id_number{gender_digit=GenderDigit})
when GenderDigit >= 5 -> male;
gender(#rsa_id_number{gender_digit=GenderDigit})
when GenderDigit < 5 -> female.

Andreas Pauley – @apauley

Types in Erlang
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Table of Contents
1

Erlang Type Overview

2

Can we add compile-time types to Erlang?

3

Optional Types

4

Dialyzer

5

Proper

6

Conclusion

Andreas Pauley – @apauley

Types in Erlang
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Discrepency Analyzer for Erlang

A static analysis tool developed by Kostis Sagonas from the
University of Uppsala in Sweden.

Andreas Pauley – @apauley

Types in Erlang
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Discrepency Analyzer for Erlang

A static analysis tool developed by Kostis Sagonas from the
University of Uppsala in Sweden.
Type inference based on Success Typing instead of
Hindley-Milner.

Andreas Pauley – @apauley

Types in Erlang
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Discrepency Analyzer for Erlang

A static analysis tool developed by Kostis Sagonas from the
University of Uppsala in Sweden.
Type inference based on Success Typing instead of
Hindley-Milner.
Doesn’t need type specifications, but you get more useful
results if you provide them.

Andreas Pauley – @apauley

Types in Erlang
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Dialyzer and Types

-type suit() :: spades | clubs | hearts | diamonds.
-type value() :: 1..10 | jack | queen | king.
-type card() :: {suit(), value()}.

Andreas Pauley – @apauley

Types in Erlang
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Dialyzer and Types

-spec kind(card()) -> face | number.
kind({_, A}) when A >= 1, A =< 10 -> number;
kind(_) -> face.
main() ->
number
face
number
face

=
=
=
=

kind({spades, 7}),
kind({hearts, king}),
kind({rubies, 4}),
kind({clubs, queen}).

Andreas Pauley – @apauley

Types in Erlang
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Dialyzer and Types

Checking whether the PLT .deps_plt is up-to-date... yes
Proceeding with analysis...
src/cards.erl:15: Function main/0 has no local return
src/cards.erl:18: The call cards:kind({’rubies’,4})
breaks the contract (card()) -> ’face’ | ’number’
done in 0m0.54s
done (warnings were emitted)
make: *** [dialyzer] Error 2

Andreas Pauley – @apauley

Types in Erlang
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Table of Contents
1

Erlang Type Overview

2

Can we add compile-time types to Erlang?

3

Optional Types

4

Dialyzer

5

Proper

6

Conclusion

Andreas Pauley – @apauley

Types in Erlang
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Discrepency Analyzer for Erlang

A QuickCheck-inspired property-based testing tool for Erlang.

Andreas Pauley – @apauley

Types in Erlang
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Discrepency Analyzer for Erlang

A QuickCheck-inspired property-based testing tool for Erlang.
Developed by Manolis Papadakis, Eirini Arvaniti and Kostis
Sagonas from the National Technical University of Athens.

Andreas Pauley – @apauley

Types in Erlang
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Discrepency Analyzer for Erlang

A QuickCheck-inspired property-based testing tool for Erlang.
Developed by Manolis Papadakis, Eirini Arvaniti and Kostis
Sagonas from the National Technical University of Athens.
Has the ability to generate random tests based on type specs.

Andreas Pauley – @apauley

Types in Erlang
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Property tests from the specs

2> proper:check_specs(rsa_id_number).
Testing rsa_id_number:checksum/1
...........................................................
OK: Passed 100 test(s).

Testing rsa_id_number:citizen/1
...........................................................
OK: Passed 100 test(s).

Testing rsa_id_number:gender/1
...........................................................
OK: Passed 100 test(s).
Andreas Pauley – @apauley

Types in Erlang
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Table of Contents
1

Erlang Type Overview

2

Can we add compile-time types to Erlang?

3

Optional Types

4

Dialyzer

5

Proper

6

Conclusion

Andreas Pauley – @apauley

Types in Erlang
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Conclusion

On its own, type declarations is maybe just a way to comment
your code.

Andreas Pauley – @apauley

Types in Erlang
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Conclusion

On its own, type declarations is maybe just a way to comment
your code.
With the extra tool support and some effort we’re getting a lot
of benefit typically only found in statically typed languages.

Andreas Pauley – @apauley

Types in Erlang
Erlang Type Overview
Can we add compile-time types to Erlang?
Optional Types
Dialyzer
Proper
Conclusion

Conclusion

On its own, type declarations is maybe just a way to comment
your code.
With the extra tool support and some effort we’re getting a lot
of benefit typically only found in statically typed languages.
It’s far from perfect.

Andreas Pauley – @apauley

Types in Erlang

Contenu connexe

Dernier

Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 

Dernier (20)

Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 

En vedette

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

En vedette (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Optional Type Specification in Erlang

  • 1. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Optional Type Specification in Erlang Andreas Pauley – @apauley Lambda Luminaries – @lambdaluminary November 11, 2013 Andreas Pauley – @apauley Types in Erlang
  • 2. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Table of Contents 1 Erlang Type Overview 2 Can we add compile-time types to Erlang? 3 Optional Types 4 Dialyzer 5 Proper 6 Conclusion Andreas Pauley – @apauley Types in Erlang
  • 3. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Dynamic, but strong example({}) -> "empty tuple"; example(List) when is_list(List) -> length(List); example(_Else) -> another_return_type. Andreas Pauley – @apauley Types in Erlang
  • 4. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Dynamic, but strong 3> 5 + "6". ** exception error: an error occurred when evaluating an arithmetic expression in operator +/2 called as 5 + "6" Andreas Pauley – @apauley Types in Erlang
  • 5. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Table of Contents 1 Erlang Type Overview 2 Can we add compile-time types to Erlang? 3 Optional Types 4 Dialyzer 5 Proper 6 Conclusion Andreas Pauley – @apauley Types in Erlang
  • 6. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Yes and No :-/ The Haskell giants Simon Marlow and Philip Wadler spent over a year developing a static type system for Erlang (circa 1997). Andreas Pauley – @apauley Types in Erlang
  • 7. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Yes and No :-/ The Haskell giants Simon Marlow and Philip Wadler spent over a year developing a static type system for Erlang (circa 1997). Only a subset of the language could be type-checked. Andreas Pauley – @apauley Types in Erlang
  • 8. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Yes and No :-/ The Haskell giants Simon Marlow and Philip Wadler spent over a year developing a static type system for Erlang (circa 1997). Only a subset of the language could be type-checked. Process types and inter-process messages could not be type-checked. Andreas Pauley – @apauley Types in Erlang
  • 9. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Table of Contents 1 Erlang Type Overview 2 Can we add compile-time types to Erlang? 3 Optional Types 4 Dialyzer 5 Proper 6 Conclusion Andreas Pauley – @apauley Types in Erlang
  • 10. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Declaring Types We can declare union/sum types and product types: -type suit() :: spades | clubs | hearts | diamonds. -type value() :: 1..10 | jack | queen | king. -type card() :: {suit(), value()}. Andreas Pauley – @apauley Types in Erlang
  • 11. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Declaring Types Types in record definitions: -record(rsa_id_number, {birth_date gender_digit sequence_nr citizen_digit digit_a checksum_digit Andreas Pauley – @apauley Types in Erlang :: :: :: :: :: :: calendar:date(), 0..9, 0..999, 0 | 1, 0..9, 0..9}).
  • 12. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Using Types -spec suit(card()) -> suit(). suit({Suit, _}) -> Suit. Andreas Pauley – @apauley Types in Erlang
  • 13. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Using Types -type gender() :: male | female. -type rsa_id_number() :: #rsa_id_number{}. -export_type([rsa_id_number/0]). -spec gender(rsa_id_number()) -> gender(). gender(#rsa_id_number{gender_digit=GenderDigit}) when GenderDigit >= 5 -> male; gender(#rsa_id_number{gender_digit=GenderDigit}) when GenderDigit < 5 -> female. Andreas Pauley – @apauley Types in Erlang
  • 14. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Table of Contents 1 Erlang Type Overview 2 Can we add compile-time types to Erlang? 3 Optional Types 4 Dialyzer 5 Proper 6 Conclusion Andreas Pauley – @apauley Types in Erlang
  • 15. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Discrepency Analyzer for Erlang A static analysis tool developed by Kostis Sagonas from the University of Uppsala in Sweden. Andreas Pauley – @apauley Types in Erlang
  • 16. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Discrepency Analyzer for Erlang A static analysis tool developed by Kostis Sagonas from the University of Uppsala in Sweden. Type inference based on Success Typing instead of Hindley-Milner. Andreas Pauley – @apauley Types in Erlang
  • 17. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Discrepency Analyzer for Erlang A static analysis tool developed by Kostis Sagonas from the University of Uppsala in Sweden. Type inference based on Success Typing instead of Hindley-Milner. Doesn’t need type specifications, but you get more useful results if you provide them. Andreas Pauley – @apauley Types in Erlang
  • 18. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Dialyzer and Types -type suit() :: spades | clubs | hearts | diamonds. -type value() :: 1..10 | jack | queen | king. -type card() :: {suit(), value()}. Andreas Pauley – @apauley Types in Erlang
  • 19. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Dialyzer and Types -spec kind(card()) -> face | number. kind({_, A}) when A >= 1, A =< 10 -> number; kind(_) -> face. main() -> number face number face = = = = kind({spades, 7}), kind({hearts, king}), kind({rubies, 4}), kind({clubs, queen}). Andreas Pauley – @apauley Types in Erlang
  • 20. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Dialyzer and Types Checking whether the PLT .deps_plt is up-to-date... yes Proceeding with analysis... src/cards.erl:15: Function main/0 has no local return src/cards.erl:18: The call cards:kind({’rubies’,4}) breaks the contract (card()) -> ’face’ | ’number’ done in 0m0.54s done (warnings were emitted) make: *** [dialyzer] Error 2 Andreas Pauley – @apauley Types in Erlang
  • 21. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Table of Contents 1 Erlang Type Overview 2 Can we add compile-time types to Erlang? 3 Optional Types 4 Dialyzer 5 Proper 6 Conclusion Andreas Pauley – @apauley Types in Erlang
  • 22. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Discrepency Analyzer for Erlang A QuickCheck-inspired property-based testing tool for Erlang. Andreas Pauley – @apauley Types in Erlang
  • 23. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Discrepency Analyzer for Erlang A QuickCheck-inspired property-based testing tool for Erlang. Developed by Manolis Papadakis, Eirini Arvaniti and Kostis Sagonas from the National Technical University of Athens. Andreas Pauley – @apauley Types in Erlang
  • 24. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Discrepency Analyzer for Erlang A QuickCheck-inspired property-based testing tool for Erlang. Developed by Manolis Papadakis, Eirini Arvaniti and Kostis Sagonas from the National Technical University of Athens. Has the ability to generate random tests based on type specs. Andreas Pauley – @apauley Types in Erlang
  • 25. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Property tests from the specs 2> proper:check_specs(rsa_id_number). Testing rsa_id_number:checksum/1 ........................................................... OK: Passed 100 test(s). Testing rsa_id_number:citizen/1 ........................................................... OK: Passed 100 test(s). Testing rsa_id_number:gender/1 ........................................................... OK: Passed 100 test(s). Andreas Pauley – @apauley Types in Erlang
  • 26. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Table of Contents 1 Erlang Type Overview 2 Can we add compile-time types to Erlang? 3 Optional Types 4 Dialyzer 5 Proper 6 Conclusion Andreas Pauley – @apauley Types in Erlang
  • 27. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Conclusion On its own, type declarations is maybe just a way to comment your code. Andreas Pauley – @apauley Types in Erlang
  • 28. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Conclusion On its own, type declarations is maybe just a way to comment your code. With the extra tool support and some effort we’re getting a lot of benefit typically only found in statically typed languages. Andreas Pauley – @apauley Types in Erlang
  • 29. Erlang Type Overview Can we add compile-time types to Erlang? Optional Types Dialyzer Proper Conclusion Conclusion On its own, type declarations is maybe just a way to comment your code. With the extra tool support and some effort we’re getting a lot of benefit typically only found in statically typed languages. It’s far from perfect. Andreas Pauley – @apauley Types in Erlang