Flow-sensitive typing: Difference between revisions

Content deleted Content added
WikiCleanerBot (talk | contribs)
m v2.04b - Bot T20 CW#61 - Fix errors for CW project (Reference before punctuation)
m Fixing style/layout errors
Line 5:
In [[Static typing|statically typed languages]], a type of an expression is determined by the types of the sub-expressions that compose it. However, in flow-sensitive typing, an expression's type may be updated to a more specific type if it follows a statement that validates its type. The type is determined by using [[type inference]] and type information is carried using [[algebraic data type]]s.
 
== ExampleExamples ==
 
=== Ceylon ===
Line 35:
</syntaxhighlight>
 
Whichand whhich outputs:
 
<nowiki>Hello, world!
Hello, object 1!
Hello, John Doe!
Line 78:
Typed Scheme, a type system for [[Scheme (programming language)|Scheme]], was the first type system with this feature.<ref>{{cite web |title=The Design and Implementation of Typed Scheme {{!}} Lambda the Ultimate, 2008 |url=http://lambda-the-ultimate.org/node/2622 |website=lambda-the-ultimate.org}}</ref> Shortly thereafter, David J. Pearce independently reinvented it in [[Whiley (programming language)|Whiley]], the first language to have this feature built-in.<ref>{{cite web | url=http://whiley.org/2010/09/22/on-flow-sensitive-types-in-whiley/ | title=On Flow-Sensitive Types in Whiley | publisher=whiley.org | date=22 September 2010 | accessdate=11 March 2016 | author=David J. Pearce}}</ref><ref>{{cite web | url=http://whiley.org/guide/typing/flow-typing/ | title=Whiley - Flow Typing | publisher=whiley.org | date=8 April 2012 | accessdate=11 March 2016 | author=David J. Pearce}}</ref>
 
The successor to Typed Scheme, Typed Racket (a dialect of [[Racket (programming language)|Racket]]), still makes extensive use of occurrence typing.<ref>{{cite web |title=5 Occurrence Typing |url=https://docs.racket-lang.org/ts-guide/occurrence-typing.html |website=docs.racket-lang.org}}</ref> It has since appeared in [[Ceylon (programming language)|Ceylon]],<ref>{{cite web | url=http://ceylon-lang.org/documentation/1.2/introduction/#typesafe_null_and_flow_sensitive_typing | title=Ceylon - Quick introduction - Typesafe null and flow-sensitive typing | publisher=ceylon-lang.org | accessdate=11 March 2016}}</ref> [[TypeScript]]<ref>{{cite web | url=https://blogs.msdn.microsoft.com/typescript/2014/11/18/typescript-1-4-sneak-peek-union-types-type-guards-and-more | title=TypeScript 1.4 sneak peek: union types, type guards, and more | publisher=blogs.msdn.microsoft.com | date=18 November 2014 | accessdate=11 March 2016 | author=Ryan Cavanaugh}}</ref> and [[Facebook]] Flow.<ref>{{cite web | url=https://code.facebook.com/posts/1505962329687926/flow-a-new-static-type-checker-for-javascript | title=Flow, a new static type checker for JavaScript | publisher=code.facebook.com | date=18 November 2014 | accessdate=11 March 2016 | authors=Avik Chaudhuri, Basil Hosmer, Gabriel Levi}}</ref>
 
There are also a few languages that don't have [[Tagged union|union types]] but do have [[nullable types]], that have a limited form of this feature that only applies to nullable types, such as [[C Sharp (programming language)|C#]],<ref>{{cite web |title=Design with nullable reference types |url=https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/nullable-reference-types#create-respondents-and-get-answers-to-the-survey |website=docs.microsoft.com |language=en-us}}</ref> [[Kotlin (programming language)|Kotlin]],<ref>{{cite web | url=https://kotlinlang.org/docs/reference/null-safety.html | title=Null Safety | publisher=kotlinlang.org | accessdate=11 March 2016}}</ref><ref>{{cite web | url=https://kotlinlang.org/docs/reference/typecasts.html | title=Type Checks and Casts | publisher=kotlinlang.org | accessdate=11 March 2016}}</ref> and Lobster.<ref>{{cite web |title=The Lobster Type System |url=http://aardappel.github.io/lobster/type_checker.html#the-trouble-with-nil |website=aardappel.github.io}}</ref>
Line 110:
In a statically typed language, the advantage of pattern matching over flow-sensitive typing is that the type of a variable always stays the same: it does not change depending on control flow. When writing down the pattern to be matched, a new variable is declared that will have the new type.
 
==References==
==External references==
<references />