SlideShare uma empresa Scribd logo
1 de 116
Baixar para ler offline
88

mph
YEAR
2016
GitHub
YEAR
440 BCE
Herodotus
“Herodotus of
Halicarnassus here
presents his research
so that human events
do not fade with
time.”
Herodotus, The Histories

Book I, Proem

trans. Andrea L. Purvis

YEAR
404 BCE
Lysander
“[Sparta] they would never
reduce to slavery a city
which was itself an integral
portion of Hellas, and had
performed a great and
noble service to Hellas in
the most perilous of
emergencies.”
Xenophon, Hellenica

Book 2, 2.20

trans. H. G. Dakyns

YEAR
399 BCE
Socrates
“[Writing offers readers] the
appearance of wisdom, not true
wisdom, for they will read many
things without instruction and
will therefore seem to know
many things, when they are for
the most part ignorant and hard
to get along with, since they are
not wise, but only appear wise.”
Plato, Phaedrus
275a-b

trans. Harold N. Fowler

YEAR
1822
Hegel
“World history is
the record of the
spirit's efforts to
attain knowledge of
what it is in itself.”
Hegel, Lectures on the
Philosophy of World History

Introduction

trans. Johannes Hoffmeister

Timeline
• Local Functions
• Tuples
• Records
• Pattern Matching
• Ref Locals / Ref Returns
• Binary Literals / Digit Separators
Timeline
• Local Functions
• Tuples
• Pattern Matching
Timeline
• Local Functions
• Tuples
• Pattern Matching
YEAR
1960
Algol 60
Local Functions

{Algol 60}
begin
comment classic recursive procedure;
integer nn, nf;
integer procedure factorial(n); value n; integer n;
begin
if n <= 1 then factorial := 1
else factorial := n * factorial(n-1)
end;
nn := 5;
nf := factorial(nn);
outinteger ( 1 , nf)
end
taken from: http://algol60.org/lego/procedure11.a60Algol 60
Local Functions

{Algol 60}
integer procedure factorial(n); value n; integer n;
begin
if n <= 1 then factorial := 1
else factorial := n * factorial(n-1)
end;
nn := 5;
nf := factorial(nn);
taken from: http://algol60.org/lego/procedure11.a60Algol 60
YEAR
2015
C# 6
Local Functions

{without language support}
private struct locals
{
public int x;
}
static void Main(string[] args)
{
var x = 42;
var local = new locals {x = x};
AddOne(ref local);
x = local.x;
WriteLine($"x + 1 = {x}");
}
private static void AddOne(ref locals implicits)
{
implicits.x += 1;
}
C# 6
YEAR
2017
C# 7
Local Functions

{with language support}
static void Main(string[] args)
{
var x = 42;
void AddOne()
{
x += 1;
}
AddOne();
WriteLine($"x + 1 = {x}");
}
C# 7
Functions
Functions

{basic}
function outputinput
Functions

{real world}
function
outputinput
effect
side

effect
Functions

{basic}
Hello Lengthname
Functions

{basic}
public int Hello(string name)
{
var time = DateTime.Now;
Console.Write($"Hello {name} it is now {time}");
return name.Length;
}
C# 6
Functions

{real world}
Hello
Lengthname
DateTime Console
Functions

{real world}
public int Hello(string name)
{
var time = DateTime.Now;
Console.Write($"Hello {name} it is now {time}");
return name.Length;
}
C# 6
YEAR
2017
C# 7
Local Functions

{“realistic”}
static void Main(string[] args)
{
var program = new Program();
IEnumerable<int> values = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
string FormatValues()
{
return string.Join(",", values);
}
Console.WriteLine($"before: {FormatValues()}");
values = program.RealistCode(values);
Console.WriteLine($"after: {FormatValues()}");
}
public IEnumerable<int> RealistCode(IEnumerable<int> values)
{
if (values == null)
throw new ArgumentException("values cannot be null");
if (!values.Any())
throw new ArgumentException("must have at least one element in values");
IEnumerable <int> Rules()
{
return values
.Where(x => x > 2)
.Where(x => x%2 == 1);
}
return Rules();
}
C# 7
Local Functions

{“realistic”}
static void Main(string[] args)
{
var program = new Program();
IEnumerable<int> values = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
string FormatValues()
{
return string.Join(",", values);
}
Console.WriteLine($"before: {FormatValues()}");
values = program.RealistCode(values);
Console.WriteLine($"after: {FormatValues()}");
}
C# 7
Local Functions

{really “realistic”}
public IEnumerable<int> RealistCode(IEnumerable<int> values)
{
if (values == null)
throw new ArgumentException("values cannot be null");
if (!values.Any())
throw new ArgumentException(
"must have at least one element in values");
IEnumerable <int> Rules()
{
return values
.Where(x => x > 2)
.Where(x => x%2 == 1);
}
return Rules();
}
C# 7
Local Functions

{really “realistic”}
public IEnumerable<int> RealistCode(IEnumerable<int> values)
{
Precondition();
return values
.Where(x => x > 2)
.Where(x => x%2 == 1);
void Precondition()
{
if (values == null)
throw new ArgumentException("values cannot be null");
if (!values.Any())
throw new ArgumentException("must have at least one element in values");
}
}
C# 7
Design

By Contract
YEAR
1985
Eiffel
Local Functions

{design by contract}
note
description : "example of factorial"
class
APPLICATION
create
make
feature -- Initialization
make
local
n: NATURAL
do
n := 3
print ("%NFactorial of " + n.out + " = ")
print (recursive_factorial (n))
end
feature -- Access
recursive_factorial (n: NATURAL): NATURAL
require
n >= 0
do
if n = 0 then
Result := 1
else
Result := n * recursive_factorial (n - 1)
end
end
end
Eiffel
Local Functions

{design by contract}
feature -- Access
recursive_factorial (n: NATURAL): NATURAL
require
n >= 0
do
if n = 0 then
Result := 1
else
Result := n * recursive_factorial (n - 1)
end
end
end
Eiffel
YEAR
2009
Clojure
Local Functions

{design by contract}
(ns com.blogspot.comp-phil.factorial)
;; no tail call optimization
(defn factorial [n]
{:pre [((comp not neg?) n)]}
(if (= n 0)
1
(* n (factorial (dec n)))))
(factorial 1)
(factorial 5)
Clojure
Local Functions

{design by contract}
(defn factorial [n]
{:pre [((comp not neg?) n)]}
(if (= n 0)
1
(* n (factorial (dec n)))))
Clojure
YEAR
2017
C# 7
Local Functions

{design by contract}
static void Main(string[] args)
{
// no tail call optimization
long Factorial(int x)
{
if (x < 0)
throw new ArgumentException(“value < 0”);
if (x <= 1) return 1;
return x * Factorial(x-1);
}
Console.WriteLine($"1! = {Factorial(1)}");
Console.WriteLine($"3! = {Factorial(3)}");
Console.WriteLine($"20! = {Factorial(20)}");
}
C# 7
Tail Call

Optimization
YEAR
2017
C# 7
Local Functions

{no tail call}
static void Main(string[] args)
{
// no tail call optimization
long Factorial(int x)
{
if (x <= 1) return 1;
return x * Factorial(x-1);
}
Console.WriteLine($"1! = {Factorial(1)}");
Console.WriteLine($"3! = {Factorial(3)}");
Console.WriteLine($"20! = {Factorial(20)}");
}
C# 7
Console.WriteLine($"3! = {Factorial(3)}");
long Factorial(int x)
{
if (x <= 1) return x;
return x * Factorial(x-1);
}
x = 3

3 * ?
C# 7
Console.WriteLine($"3! = {Factorial(3)}");
long Factorial(int x)
{
if (x <= 1) return x;
return x * Factorial(x-1);
}
x = 3

3 *
x = 2

2 * ?
C# 7
Console.WriteLine($"3! = {Factorial(3)}");
x = 3

3 *
long Factorial(int x)
{
if (x <= 1) return x;
return x * Factorial(x-1);
}
x = 2

2 *
x = 1

1
C# 7
Console.WriteLine($"3! = {Factorial(3)}");
x = 3

3 *
long Factorial(int x)
{
if (x <= 1) return x;
return x * Factorial(x-1);
}
x = 2

2
C# 7
Console.WriteLine($"3! = {Factorial(3)}");
x = 3

6
long Factorial(int x)
{
if (x <= 1) return x;
return x * Factorial(x-1);
}
C# 7
Local Functions

{tail call}
static void Main(string[] args)
{
// would have tail call optimization if supported
long Factorial(int x)
{
long Aux(long acc, int n)
{
if (n <= 1) return acc;
return Aux(acc * n, n - 1);
}
return Aux(1, x);
}
Console.WriteLine($"1! = {Factorial(1)}");
Console.WriteLine($"3! = {Factorial(3)}");
Console.WriteLine($"20! = {Factorial(20)}");
}
C# 7
Console.WriteLine($"3! = {Factorial(3)}");
acc = 1

n = 3
long Aux(long acc, int n)
{
if (n <= 1) return acc;
return Aux(acc * n, n - 1);
}
C# 7
Console.WriteLine($"3! = {Factorial(3)}");
acc = 1

n = 3
acc = 3

n = 2
long Aux(long acc, int n)
{
if (n <= 1) return acc;
return Aux(acc * n, n - 1);
}
C# 7
Console.WriteLine($"3! = {Factorial(3)}");
acc = 1

n = 3
acc = 3

n = 2
acc = 6

n = 1
long Aux(long acc, int n)
{
if (n <= 1) return acc;
return Aux(acc * n, n - 1);
}
C# 7
Local Functions

{“tail call optimization”}
static void Main(string[] args)
{
// simulated tail call optimization
long Factorial(int n)
{
long acc = 1;
top:
if (n <= 1) return acc;
acc *= n;
n--;
goto top;
}
Console.WriteLine($"1! = {Factorial(1)}");
Console.WriteLine($"3! = {Factorial(3)}");
Console.WriteLine($"20! = {Factorial(20)}");
}
C# 7
Local Functions

{“tail call optimization”}
static void Main(string[] args)
{
// simulated tail call optimization
long Factorial(int n)
{
long acc = 1;
top:
if (n <= 1) return acc;
acc *= n;
n--;
goto top;
}
Console.WriteLine($"1! = {Factorial(1)}");
Console.WriteLine($"3! = {Factorial(3)}");
Console.WriteLine($"20! = {Factorial(20)}");
}
C# 7
Console.WriteLine($"3! = {Factorial(3)}");
acc = 1

n = 3
long Factorial(int n)
{
long acc = 1;
top:
if (n <= 1) return acc;
acc *= n;
n--;
goto top;
}C# 7
Console.WriteLine($"3! = {Factorial(3)}");
acc = 3

n = 2
long Factorial(int n)
{
long acc = 1;
top:
if (n <= 1) return acc;
acc *= n;
n--;
goto top;
}C# 7
Console.WriteLine($"3! = {Factorial(3)}");
acc = 6

n = 1
long Factorial(int n)
{
long acc = 1;
top:
if (n <= 1) return acc;
acc *= n;
n--;
goto top;
}C# 7
YEAR
2010
F#
Local Functions

{tail call optimization}
F#
module Factorial =
let factorial x =
let rec aux m x =
match x with
| 0 -> m
| _ -> aux (m*x) (x-1)
aux 1 x
Timeline
• Local Functions
• Tuples
• Pattern Matching
Tuples
tuple
item 1 item 2
Tuples
“Hello” 42
YEAR
2010
C# 4.0
Tuple

{mostly everything}
static void Main(string[] args)
{
Console.WriteLine("1! = “ + Factorial(1));
Console.WriteLine("5! = “ + Factorial(5));
Console.WriteLine("20! = “ + Factorial(20));
}
private static long Factorial(int x)
{
return FactorialAux(new Tuple<int, int>(1, x));
}
private static long FactorialAux(Tuple<int, int> t)
{
if (t.Item2 <= 1) return t.Item1;
var r = new Tuple<int, int>(t.Item1*t.Item2, t.Item2 - 1);
return FactorialAux(r);
}
C# 4.0
YEAR
2017
C# 7
Tuple

{mostly everything}
static void Main(string[] args)
{
long Factorial(int x)
{
long Aux((int acc, int n) a)
{
if (a.n <= 1) return a.acc;
var r = (a.acc * a.n, a.n - 1);
return Aux(r);
}
(int, int) t = (1, x);
return Aux(t);
}
Console.WriteLine($"1! = {Factorial(1)}");
Console.WriteLine($"3! = {Factorial(3)}");
Console.WriteLine($"20! = {Factorial(20)}");
}
C# 7
Timeline
• Local Functions
• Tuples
• Pattern Matching
Pattern Matching
type 1
type 2
other
type 2 Matcher
YEAR
2010
C# 4.0
Pattern Matching

{types}
static void Main(string[] args)
{
var values = new List<object>
{1, (short) 2,
(Int32) 3, null,
new {}, "no", 1.2d};
foreach (var value in values)
{
var x = value as int;
if (x != null)
Console.WriteLine("got “ + x);
}
}
C# 4.0
YEAR
2017
C# 7
Pattern Matching

{types}
static void Main(string[] args)
{
var values = new List<object>
{1, (short) 2,
(Int32) 3, null,
new {}, "no", 1.2d};
foreach (var value in values)
{
if (value is int x)
Console.WriteLine($"got {x}");
}
}
C# 7
Function

Pattern

Matching
YEAR
1973
ML
Pattern Matching

{functional pattern matching}
fun factorial(0) = 1
| factorial(n) = n * factorial(n-1);
print(
"5! =" ^ (Int.toString (factorial(5))) ^ "n");
ML
YEAR
2004
Scala
Pattern Matching

{functional pattern matching}
import scala.annotation.tailrec
object factorial {
def apply(x: Int): Int = {
@tailrec
def go(m: Int, x: Int): Int = x match {
case 0 => m
case _ => go(x*m, x-1)
}
go(1, x)
}
}
println(s"5! = ${factorial(5)}")
Scala
YEAR
2018
C# 8
Pattern Matching

{functional pattern matching}
long Factorial(int x)
{
long Aux(int m, int x)
{
match(x)
{
case 0: return m;
default: return Aux(x*m, x-1);
}
}
return Aux(1, x);
}
Console.WriteLine($"5! = {Factorial(5)}");
C# 8
YEAR
2018
C# 8
Pattern Matching

{types}
static void Main(string[] args)
{
var values = new List<object>
{1, (short) 2,
(Int32) 3, null,
new {}, "no", 1.2d};
foreach (var value in values)
{
t = match(x)
{
case int _: "int";
case short _: "short";
case object _: "object";
case string _: "string";
default: "something";
}
Console.WriteLine("got “ + t);
}
}
C# 8
Pattern Matching

{types}
foreach (var value in values)
{
t = match(x)
{
case int _: "int";
case short _: "short";
case object _: "object";
case string _: "string";
default: "something";
}
Console.WriteLine("got “ + t);
}
C# 8
Thank you!
Mike Harris



@MikeMKH

http://comp-phil.blogspot.com/
Biography
• Tomas Petricek - "Coeffects: Context-aware programming
languages" http://tomasp.net/coeffects/
• https://github.com/dotnet/roslyn/blob/features/patterns/
docs/features/local-functions.md
• https://github.com/dotnet/roslyn/issues/347
• https://github.com/dotnet/roslyn/blob/features/patterns/
docs/features/patterns.md
• https://github.com/dotnet/roslyn/blob/master/docs/
Language%20Feature%20Status.md
Images
• DeLorean DMC-12 by en:user:Grenex - Wikipedia en, CC BY-SA 3.0,
https://commons.wikimedia.org/w/index.php?curid=2500249
• Herodotos by © Marie-Lan Nguyen / Wikimedia Commons, Public
Domain, https://commons.wikimedia.org/w/index.php?curid=12886457
• Lysander by Walter Crane - The story of Greece : told to boys and girls
(191-?) by Macgregor, Mary, Public Domain, https://
commons.wikimedia.org/w/index.php?curid=32804563
• Socrates by Walter Crane - The story of Greece : told to boys and girls
(191-?) by Macgregor, Mary, Public Domain, https://
commons.wikimedia.org/w/index.php?curid=32804549
• Hegel by Unknown - http://portrait.kaar.at/, Public Domain, https://
commons.wikimedia.org/w/index.php?curid=3308762

Mais conteúdo relacionado

Mais procurados

"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей Коваленко"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
Fwdays
 
Java 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forwardJava 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forward
Mario Fusco
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
Mario Fusco
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
Dmitry Buzdin
 
C# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewC# 6.0 - April 2014 preview
C# 6.0 - April 2014 preview
Paulo Morgado
 

Mais procurados (20)

Java Class Design
Java Class DesignJava Class Design
Java Class Design
 
TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...
TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...
TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...
 
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDBTDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Data
 
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей Коваленко"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
 
Haskell in the Real World
Haskell in the Real WorldHaskell in the Real World
Haskell in the Real World
 
Java 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forwardJava 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forward
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
 
Why Haskell
Why HaskellWhy Haskell
Why Haskell
 
3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в Java3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в Java
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
ES6 in Real Life
ES6 in Real LifeES6 in Real Life
ES6 in Real Life
 
C# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewC# 6.0 - April 2014 preview
C# 6.0 - April 2014 preview
 
PDBC
PDBCPDBC
PDBC
 
Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative Practice
 
Talk - Query monad
Talk - Query monad Talk - Query monad
Talk - Query monad
 
Sneaking inside Kotlin features
Sneaking inside Kotlin featuresSneaking inside Kotlin features
Sneaking inside Kotlin features
 
Map(), flatmap() and reduce() are your new best friends: simpler collections,...
Map(), flatmap() and reduce() are your new best friends: simpler collections,...Map(), flatmap() and reduce() are your new best friends: simpler collections,...
Map(), flatmap() and reduce() are your new best friends: simpler collections,...
 
EcmaScript 6
EcmaScript 6 EcmaScript 6
EcmaScript 6
 
Type Driven Development with TypeScript
Type Driven Development with TypeScriptType Driven Development with TypeScript
Type Driven Development with TypeScript
 

Destaque

Destaque (20)

The Little Wonders of C# 6
The Little Wonders of C# 6The Little Wonders of C# 6
The Little Wonders of C# 6
 
What's new in c# 6
What's new in c# 6What's new in c# 6
What's new in c# 6
 
Of Lambdas and LINQ
Of Lambdas and LINQOf Lambdas and LINQ
Of Lambdas and LINQ
 
C# 7
C# 7C# 7
C# 7
 
Donetconf2016: The Future of C#
Donetconf2016: The Future of C#Donetconf2016: The Future of C#
Donetconf2016: The Future of C#
 
Python for the C# developer
Python for the C# developerPython for the C# developer
Python for the C# developer
 
Automating C# Coding Standards using StyleCop and FxCop
Automating C# Coding Standards using StyleCop and FxCopAutomating C# Coding Standards using StyleCop and FxCop
Automating C# Coding Standards using StyleCop and FxCop
 
More Little Wonders of C#/.NET
More Little Wonders of C#/.NETMore Little Wonders of C#/.NET
More Little Wonders of C#/.NET
 
C# and the Evolution of a Programming Language
C# and the Evolution of a Programming LanguageC# and the Evolution of a Programming Language
C# and the Evolution of a Programming Language
 
C# features through examples
C# features through examplesC# features through examples
C# features through examples
 
Evolution of c# - by K.Jegan
Evolution of c# - by K.JeganEvolution of c# - by K.Jegan
Evolution of c# - by K.Jegan
 
Haskell vs. F# vs. Scala
Haskell vs. F# vs. ScalaHaskell vs. F# vs. Scala
Haskell vs. F# vs. Scala
 
Future of .NET - .NET on Non Windows Platforms
Future of .NET - .NET on Non Windows PlatformsFuture of .NET - .NET on Non Windows Platforms
Future of .NET - .NET on Non Windows Platforms
 
Writing clean code in C# and .NET
Writing clean code in C# and .NETWriting clean code in C# and .NET
Writing clean code in C# and .NET
 
.NET and C# introduction
.NET and C# introduction.NET and C# introduction
.NET and C# introduction
 
C# Tutorial
C# Tutorial C# Tutorial
C# Tutorial
 
Angular 2 - Core Concepts
Angular 2 - Core ConceptsAngular 2 - Core Concepts
Angular 2 - Core Concepts
 
Игорь Фесенко "What’s New in C# 7.0"
Игорь Фесенко "What’s New in C# 7.0"Игорь Фесенко "What’s New in C# 7.0"
Игорь Фесенко "What’s New in C# 7.0"
 
C# conventions & good practices
C# conventions & good practicesC# conventions & good practices
C# conventions & good practices
 
C# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoringC# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoring
 

Semelhante a C# 7

Lecture 5: Functional Programming
Lecture 5: Functional ProgrammingLecture 5: Functional Programming
Lecture 5: Functional Programming
Eelco Visser
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class Functions
Eelco Visser
 

Semelhante a C# 7 (20)

Think Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJSThink Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJS
 
C# 6 and 7 and Futures 20180607
C# 6 and 7 and Futures 20180607C# 6 and 7 and Futures 20180607
C# 6 and 7 and Futures 20180607
 
Writing a compiler in go
Writing a compiler in goWriting a compiler in go
Writing a compiler in go
 
Kotlin Austin Droids April 14 2016
Kotlin Austin Droids April 14 2016Kotlin Austin Droids April 14 2016
Kotlin Austin Droids April 14 2016
 
Roslyn and C# 6.0 New Features
Roslyn and C# 6.0 New FeaturesRoslyn and C# 6.0 New Features
Roslyn and C# 6.0 New Features
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projects
 
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
 
Дмитрий Верескун «Синтаксический сахар C#»
Дмитрий Верескун «Синтаксический сахар C#»Дмитрий Верескун «Синтаксический сахар C#»
Дмитрий Верескун «Синтаксический сахар C#»
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchained
 
C++ manual Report Full
C++ manual Report FullC++ manual Report Full
C++ manual Report Full
 
Functional Programming You Already Know
Functional Programming You Already KnowFunctional Programming You Already Know
Functional Programming You Already Know
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
What's in Kotlin for us - Alexandre Greschon, MyHeritage
What's in Kotlin for us - Alexandre Greschon, MyHeritageWhat's in Kotlin for us - Alexandre Greschon, MyHeritage
What's in Kotlin for us - Alexandre Greschon, MyHeritage
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
Javascript
JavascriptJavascript
Javascript
 
Effective Object Oriented Design in Cpp
Effective Object Oriented Design in CppEffective Object Oriented Design in Cpp
Effective Object Oriented Design in Cpp
 
Lecture 5: Functional Programming
Lecture 5: Functional ProgrammingLecture 5: Functional Programming
Lecture 5: Functional Programming
 
Reactive Programming Patterns with RxSwift
Reactive Programming Patterns with RxSwiftReactive Programming Patterns with RxSwift
Reactive Programming Patterns with RxSwift
 
Monadologie
MonadologieMonadologie
Monadologie
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class Functions
 

Mais de Mike Harris

Mais de Mike Harris (10)

A Divine Data Comedy
A Divine Data ComedyA Divine Data Comedy
A Divine Data Comedy
 
Combinators - Lightning Talk
Combinators - Lightning TalkCombinators - Lightning Talk
Combinators - Lightning Talk
 
Hiking through the Functional Forest with Fizz Buzz
Hiking through the Functional Forest with Fizz BuzzHiking through the Functional Forest with Fizz Buzz
Hiking through the Functional Forest with Fizz Buzz
 
Coding f#un
Coding f#unCoding f#un
Coding f#un
 
All You Need is Fold in the Key of C#
All You Need is Fold in the Key of C#All You Need is Fold in the Key of C#
All You Need is Fold in the Key of C#
 
All You Need is Fold
All You Need is FoldAll You Need is Fold
All You Need is Fold
 
There and Back Again
There and Back AgainThere and Back Again
There and Back Again
 
The Marvelous Land of Higher Order Functions
The Marvelous Land of Higher Order FunctionsThe Marvelous Land of Higher Order Functions
The Marvelous Land of Higher Order Functions
 
Testing the Next Generation
Testing the Next GenerationTesting the Next Generation
Testing the Next Generation
 
Learn You a Functional JavaScript for Great Good
Learn You a Functional JavaScript for Great GoodLearn You a Functional JavaScript for Great Good
Learn You a Functional JavaScript for Great Good
 

Último

Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Último (20)

%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 

C# 7

  • 1.
  • 2.
  • 4.
  • 6.
  • 7.
  • 9. “Herodotus of Halicarnassus here presents his research so that human events do not fade with time.” Herodotus, The Histories
 Book I, Proem
 trans. Andrea L. Purvis

  • 10.
  • 12. “[Sparta] they would never reduce to slavery a city which was itself an integral portion of Hellas, and had performed a great and noble service to Hellas in the most perilous of emergencies.” Xenophon, Hellenica
 Book 2, 2.20
 trans. H. G. Dakyns

  • 13.
  • 15. “[Writing offers readers] the appearance of wisdom, not true wisdom, for they will read many things without instruction and will therefore seem to know many things, when they are for the most part ignorant and hard to get along with, since they are not wise, but only appear wise.” Plato, Phaedrus 275a-b
 trans. Harold N. Fowler

  • 16.
  • 18. “World history is the record of the spirit's efforts to attain knowledge of what it is in itself.” Hegel, Lectures on the Philosophy of World History
 Introduction
 trans. Johannes Hoffmeister

  • 19.
  • 20. Timeline • Local Functions • Tuples • Records • Pattern Matching • Ref Locals / Ref Returns • Binary Literals / Digit Separators
  • 21. Timeline • Local Functions • Tuples • Pattern Matching
  • 22.
  • 23. Timeline • Local Functions • Tuples • Pattern Matching
  • 24.
  • 26. Local Functions
 {Algol 60} begin comment classic recursive procedure; integer nn, nf; integer procedure factorial(n); value n; integer n; begin if n <= 1 then factorial := 1 else factorial := n * factorial(n-1) end; nn := 5; nf := factorial(nn); outinteger ( 1 , nf) end taken from: http://algol60.org/lego/procedure11.a60Algol 60
  • 27. Local Functions
 {Algol 60} integer procedure factorial(n); value n; integer n; begin if n <= 1 then factorial := 1 else factorial := n * factorial(n-1) end; nn := 5; nf := factorial(nn); taken from: http://algol60.org/lego/procedure11.a60Algol 60
  • 28.
  • 30. Local Functions
 {without language support} private struct locals { public int x; } static void Main(string[] args) { var x = 42; var local = new locals {x = x}; AddOne(ref local); x = local.x; WriteLine($"x + 1 = {x}"); } private static void AddOne(ref locals implicits) { implicits.x += 1; } C# 6
  • 31.
  • 33. Local Functions
 {with language support} static void Main(string[] args) { var x = 42; void AddOne() { x += 1; } AddOne(); WriteLine($"x + 1 = {x}"); } C# 7
  • 38. Functions
 {basic} public int Hello(string name) { var time = DateTime.Now; Console.Write($"Hello {name} it is now {time}"); return name.Length; } C# 6
  • 40. Functions
 {real world} public int Hello(string name) { var time = DateTime.Now; Console.Write($"Hello {name} it is now {time}"); return name.Length; } C# 6
  • 41.
  • 43. Local Functions
 {“realistic”} static void Main(string[] args) { var program = new Program(); IEnumerable<int> values = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; string FormatValues() { return string.Join(",", values); } Console.WriteLine($"before: {FormatValues()}"); values = program.RealistCode(values); Console.WriteLine($"after: {FormatValues()}"); } public IEnumerable<int> RealistCode(IEnumerable<int> values) { if (values == null) throw new ArgumentException("values cannot be null"); if (!values.Any()) throw new ArgumentException("must have at least one element in values"); IEnumerable <int> Rules() { return values .Where(x => x > 2) .Where(x => x%2 == 1); } return Rules(); } C# 7
  • 44. Local Functions
 {“realistic”} static void Main(string[] args) { var program = new Program(); IEnumerable<int> values = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; string FormatValues() { return string.Join(",", values); } Console.WriteLine($"before: {FormatValues()}"); values = program.RealistCode(values); Console.WriteLine($"after: {FormatValues()}"); } C# 7
  • 45. Local Functions
 {really “realistic”} public IEnumerable<int> RealistCode(IEnumerable<int> values) { if (values == null) throw new ArgumentException("values cannot be null"); if (!values.Any()) throw new ArgumentException( "must have at least one element in values"); IEnumerable <int> Rules() { return values .Where(x => x > 2) .Where(x => x%2 == 1); } return Rules(); } C# 7
  • 46. Local Functions
 {really “realistic”} public IEnumerable<int> RealistCode(IEnumerable<int> values) { Precondition(); return values .Where(x => x > 2) .Where(x => x%2 == 1); void Precondition() { if (values == null) throw new ArgumentException("values cannot be null"); if (!values.Any()) throw new ArgumentException("must have at least one element in values"); } } C# 7
  • 49. Local Functions
 {design by contract} note description : "example of factorial" class APPLICATION create make feature -- Initialization make local n: NATURAL do n := 3 print ("%NFactorial of " + n.out + " = ") print (recursive_factorial (n)) end feature -- Access recursive_factorial (n: NATURAL): NATURAL require n >= 0 do if n = 0 then Result := 1 else Result := n * recursive_factorial (n - 1) end end end Eiffel
  • 50. Local Functions
 {design by contract} feature -- Access recursive_factorial (n: NATURAL): NATURAL require n >= 0 do if n = 0 then Result := 1 else Result := n * recursive_factorial (n - 1) end end end Eiffel
  • 51.
  • 53. Local Functions
 {design by contract} (ns com.blogspot.comp-phil.factorial) ;; no tail call optimization (defn factorial [n] {:pre [((comp not neg?) n)]} (if (= n 0) 1 (* n (factorial (dec n))))) (factorial 1) (factorial 5) Clojure
  • 54. Local Functions
 {design by contract} (defn factorial [n] {:pre [((comp not neg?) n)]} (if (= n 0) 1 (* n (factorial (dec n))))) Clojure
  • 55.
  • 57. Local Functions
 {design by contract} static void Main(string[] args) { // no tail call optimization long Factorial(int x) { if (x < 0) throw new ArgumentException(“value < 0”); if (x <= 1) return 1; return x * Factorial(x-1); } Console.WriteLine($"1! = {Factorial(1)}"); Console.WriteLine($"3! = {Factorial(3)}"); Console.WriteLine($"20! = {Factorial(20)}"); } C# 7
  • 60. Local Functions
 {no tail call} static void Main(string[] args) { // no tail call optimization long Factorial(int x) { if (x <= 1) return 1; return x * Factorial(x-1); } Console.WriteLine($"1! = {Factorial(1)}"); Console.WriteLine($"3! = {Factorial(3)}"); Console.WriteLine($"20! = {Factorial(20)}"); } C# 7
  • 61. Console.WriteLine($"3! = {Factorial(3)}"); long Factorial(int x) { if (x <= 1) return x; return x * Factorial(x-1); } x = 3
 3 * ? C# 7
  • 62. Console.WriteLine($"3! = {Factorial(3)}"); long Factorial(int x) { if (x <= 1) return x; return x * Factorial(x-1); } x = 3
 3 * x = 2
 2 * ? C# 7
  • 63. Console.WriteLine($"3! = {Factorial(3)}"); x = 3
 3 * long Factorial(int x) { if (x <= 1) return x; return x * Factorial(x-1); } x = 2
 2 * x = 1
 1 C# 7
  • 64. Console.WriteLine($"3! = {Factorial(3)}"); x = 3
 3 * long Factorial(int x) { if (x <= 1) return x; return x * Factorial(x-1); } x = 2
 2 C# 7
  • 65. Console.WriteLine($"3! = {Factorial(3)}"); x = 3
 6 long Factorial(int x) { if (x <= 1) return x; return x * Factorial(x-1); } C# 7
  • 66.
  • 67. Local Functions
 {tail call} static void Main(string[] args) { // would have tail call optimization if supported long Factorial(int x) { long Aux(long acc, int n) { if (n <= 1) return acc; return Aux(acc * n, n - 1); } return Aux(1, x); } Console.WriteLine($"1! = {Factorial(1)}"); Console.WriteLine($"3! = {Factorial(3)}"); Console.WriteLine($"20! = {Factorial(20)}"); } C# 7
  • 68. Console.WriteLine($"3! = {Factorial(3)}"); acc = 1
 n = 3 long Aux(long acc, int n) { if (n <= 1) return acc; return Aux(acc * n, n - 1); } C# 7
  • 69. Console.WriteLine($"3! = {Factorial(3)}"); acc = 1
 n = 3 acc = 3
 n = 2 long Aux(long acc, int n) { if (n <= 1) return acc; return Aux(acc * n, n - 1); } C# 7
  • 70. Console.WriteLine($"3! = {Factorial(3)}"); acc = 1
 n = 3 acc = 3
 n = 2 acc = 6
 n = 1 long Aux(long acc, int n) { if (n <= 1) return acc; return Aux(acc * n, n - 1); } C# 7
  • 71.
  • 72. Local Functions
 {“tail call optimization”} static void Main(string[] args) { // simulated tail call optimization long Factorial(int n) { long acc = 1; top: if (n <= 1) return acc; acc *= n; n--; goto top; } Console.WriteLine($"1! = {Factorial(1)}"); Console.WriteLine($"3! = {Factorial(3)}"); Console.WriteLine($"20! = {Factorial(20)}"); } C# 7
  • 73. Local Functions
 {“tail call optimization”} static void Main(string[] args) { // simulated tail call optimization long Factorial(int n) { long acc = 1; top: if (n <= 1) return acc; acc *= n; n--; goto top; } Console.WriteLine($"1! = {Factorial(1)}"); Console.WriteLine($"3! = {Factorial(3)}"); Console.WriteLine($"20! = {Factorial(20)}"); } C# 7
  • 74. Console.WriteLine($"3! = {Factorial(3)}"); acc = 1
 n = 3 long Factorial(int n) { long acc = 1; top: if (n <= 1) return acc; acc *= n; n--; goto top; }C# 7
  • 75. Console.WriteLine($"3! = {Factorial(3)}"); acc = 3
 n = 2 long Factorial(int n) { long acc = 1; top: if (n <= 1) return acc; acc *= n; n--; goto top; }C# 7
  • 76. Console.WriteLine($"3! = {Factorial(3)}"); acc = 6
 n = 1 long Factorial(int n) { long acc = 1; top: if (n <= 1) return acc; acc *= n; n--; goto top; }C# 7
  • 77.
  • 79. Local Functions
 {tail call optimization} F# module Factorial = let factorial x = let rec aux m x = match x with | 0 -> m | _ -> aux (m*x) (x-1) aux 1 x
  • 80.
  • 81. Timeline • Local Functions • Tuples • Pattern Matching
  • 84.
  • 86. Tuple
 {mostly everything} static void Main(string[] args) { Console.WriteLine("1! = “ + Factorial(1)); Console.WriteLine("5! = “ + Factorial(5)); Console.WriteLine("20! = “ + Factorial(20)); } private static long Factorial(int x) { return FactorialAux(new Tuple<int, int>(1, x)); } private static long FactorialAux(Tuple<int, int> t) { if (t.Item2 <= 1) return t.Item1; var r = new Tuple<int, int>(t.Item1*t.Item2, t.Item2 - 1); return FactorialAux(r); } C# 4.0
  • 87.
  • 89. Tuple
 {mostly everything} static void Main(string[] args) { long Factorial(int x) { long Aux((int acc, int n) a) { if (a.n <= 1) return a.acc; var r = (a.acc * a.n, a.n - 1); return Aux(r); } (int, int) t = (1, x); return Aux(t); } Console.WriteLine($"1! = {Factorial(1)}"); Console.WriteLine($"3! = {Factorial(3)}"); Console.WriteLine($"20! = {Factorial(20)}"); } C# 7
  • 90.
  • 91. Timeline • Local Functions • Tuples • Pattern Matching
  • 92. Pattern Matching type 1 type 2 other type 2 Matcher
  • 93.
  • 95. Pattern Matching
 {types} static void Main(string[] args) { var values = new List<object> {1, (short) 2, (Int32) 3, null, new {}, "no", 1.2d}; foreach (var value in values) { var x = value as int; if (x != null) Console.WriteLine("got “ + x); } } C# 4.0
  • 96.
  • 98. Pattern Matching
 {types} static void Main(string[] args) { var values = new List<object> {1, (short) 2, (Int32) 3, null, new {}, "no", 1.2d}; foreach (var value in values) { if (value is int x) Console.WriteLine($"got {x}"); } } C# 7
  • 101. Pattern Matching
 {functional pattern matching} fun factorial(0) = 1 | factorial(n) = n * factorial(n-1); print( "5! =" ^ (Int.toString (factorial(5))) ^ "n"); ML
  • 102.
  • 104. Pattern Matching
 {functional pattern matching} import scala.annotation.tailrec object factorial { def apply(x: Int): Int = { @tailrec def go(m: Int, x: Int): Int = x match { case 0 => m case _ => go(x*m, x-1) } go(1, x) } } println(s"5! = ${factorial(5)}") Scala
  • 105.
  • 107. Pattern Matching
 {functional pattern matching} long Factorial(int x) { long Aux(int m, int x) { match(x) { case 0: return m; default: return Aux(x*m, x-1); } } return Aux(1, x); } Console.WriteLine($"5! = {Factorial(5)}"); C# 8
  • 108.
  • 110. Pattern Matching
 {types} static void Main(string[] args) { var values = new List<object> {1, (short) 2, (Int32) 3, null, new {}, "no", 1.2d}; foreach (var value in values) { t = match(x) { case int _: "int"; case short _: "short"; case object _: "object"; case string _: "string"; default: "something"; } Console.WriteLine("got “ + t); } } C# 8
  • 111. Pattern Matching
 {types} foreach (var value in values) { t = match(x) { case int _: "int"; case short _: "short"; case object _: "object"; case string _: "string"; default: "something"; } Console.WriteLine("got “ + t); } C# 8
  • 112.
  • 114.
  • 115. Biography • Tomas Petricek - "Coeffects: Context-aware programming languages" http://tomasp.net/coeffects/ • https://github.com/dotnet/roslyn/blob/features/patterns/ docs/features/local-functions.md • https://github.com/dotnet/roslyn/issues/347 • https://github.com/dotnet/roslyn/blob/features/patterns/ docs/features/patterns.md • https://github.com/dotnet/roslyn/blob/master/docs/ Language%20Feature%20Status.md
  • 116. Images • DeLorean DMC-12 by en:user:Grenex - Wikipedia en, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=2500249 • Herodotos by © Marie-Lan Nguyen / Wikimedia Commons, Public Domain, https://commons.wikimedia.org/w/index.php?curid=12886457 • Lysander by Walter Crane - The story of Greece : told to boys and girls (191-?) by Macgregor, Mary, Public Domain, https:// commons.wikimedia.org/w/index.php?curid=32804563 • Socrates by Walter Crane - The story of Greece : told to boys and girls (191-?) by Macgregor, Mary, Public Domain, https:// commons.wikimedia.org/w/index.php?curid=32804549 • Hegel by Unknown - http://portrait.kaar.at/, Public Domain, https:// commons.wikimedia.org/w/index.php?curid=3308762