SlideShare ist ein Scribd-Unternehmen logo
1 von 52
Functional Programming in Pattern-
Match-Oriented Programming Style
<Programming> 2020 Research Paper
Mar 22-26th, 2021
Satoshi Egi (Rakuten Institute of Technology, Rakuten, Inc.)
Yuichi Nishiwaki (The University of Tokyo)
Part 1. Motivation
2
3
How do you explain the map function?
map (x -> x + 10) [1, 2, 3]
-- [11, 12, 13]
The map function takes a function and a list, and returns a list of the
results of applying the function to all the elements of the list.
No one explain like this:
The map function takes a function and a list, and returns an empty list if
the argument list is empty. Otherwise, it returns a list whose head element
is the result of applying the function to the head element of the argument
list, and the tail part is the result of applying the map function recursively
to the tail part of the argument list.
However, the standard functional definition is similar to this explanation:
map f [] := []
map f (x :: xs) := f x :: map f xs
The mapWithBothSides function
4
Let us consider a variation of map, mapWithBothSides.
mapWithBothSides (hs, x, ts -> (hs, x, ts)) [1, 2, 3]
-- [([], 1, [2, 3]),
([1], 2, [3])]),
([1, 2], 3, [])]
mapWithBothSides (hs, _, ts -> hs ++ ts) [1, 2, 3]
-- [[2, 3],
[1, 3],
[1, 2]]
The mapWithBothSides function
5
Functional definition of mapWithBothSides:
mapWithBothSides f xs := helper f [] xs
where
helper f xs [] := []
helper f xs (y :: ys) := f xs y ys :: helper f (xs ++ [y]) ys
It is natural to use a helper function for defining mapWithBothSides.
Explanation of mapWithBothSides:
• takes a function of three arguments and a list, and
• returns a list of applying the function for all three-tuples consisting of an
initial prefix, the next element, and the remaining suffix.
The gap between the explanation and definition
6
The explanations of map and mapWithBothSides are very similar, but the
definitions are very different.
map f [] := []
map f (x :: xs) := f x :: map f xs
mapWithBothSides f xs := helper f [] xs
where
helper f xs [] := []
helper f xs (y :: ys) := f xs y ys :: helper f (xs ++ [y]) ys
Can we fill this cognitive gap between the explanation and definition?
Pattern matching fills the gap
7
User-extensible non-linear pattern matching with backtracking [Egi and
Nishiwaki, 2018] implemented in the Egison programming language can fill
the gap.
map f xs := matchAll xs as list something with
| _ ++ $x :: _ -> f x
mapWithBothSides f xs := matchAll xs as list something with
| $hs ++ $x :: $ts -> f hs x ts
The join pattern (++) splits a list to an initial prefix and the remaining suffix.
The cons pattern (::) decomposes a list to the initial element and the rest.
matchAll collects all
pattern-match results.
list something is a matcher and
specifies how to interpret the pattern.
$hs ++ $x :: $ts is a pattern that splits the target list into an initial prefix,
the next element, and the remaining suffix.
Our approach: pattern-match-oriented programming (PMOP)
8
mapWithBothSides f xs = helper f [] xs
where
helper f xs [] := []
helper f xs (y : : ys) := (f xs y ys) :: (helper f (xs ++ [y]) ys)
mapWithBothSides f xs := matchAll xs as list something with
| $hs ++ $x :: $ts -> f hs x ts
• Our key insight: recursions can be confined in patterns.
• In this case, $hs ++ $x :: $ts confines helper.
• We call the programming style that confines explicit recursions in
patterns, pattern-match-oriented programming (PMOP).
• We aim to clarify what is PMOP by showing PMOP examples we found so
far.
Traditional FP
Our approach
Organization of this presentation
9
Part 1. Motivation
Part 2. Features of our PMOP language
Part 3. PMOP design patterns
Part 4. PMOP in action
10
Part 1. Motivation
Part 2. Features of our PMOP language
Part 3. PMOP design patterns
Part 4. PMOP in action
Our PMOP language (Egison)
11
We demonstrate PMOP with our language Egison.
Egison was originally designed for concise description of algorithms with
non-free data types such as multisets, graphs, mathematical expressions
[Egi and Nishiwaki, 2018].
Egison has achieved this mission by user-extensible non-linear pattern-
match facility with backtracking.
Free data types Non-free data types
Consed lists,
Syntax trees,
...etc.
Multisets, Sets, Graphs,
Mathematical
expressions,
...etc.
The history of pattern matching
12
[Burstall, 1969]
Views
[Wadler, 1987]
Active patterns
[Erwig, 1996]
First class patterns
[Tullsen, 2000]
[Queinnec, 1990]
Egison
[Egi and Nishiwaki, 2018]
non-linear pattern,
multiple results
user-extensible pattern,
polymorphic pattern
user-extensible pattern
non-linear pattern
multiple results
multiple results,
polymorphic pattern
non-linear pattern,
polymorphic pattern
loop pattern, sequential pattern, ...
Our PMOP language (Egison)
13
Let us see how these features are achieved in Egison:
1. Non-linear pattern matching with multiple results [Egi and Nishiwaki, 2018]
2. Ad-hoc polymorphism of patterns by matchers [Egi and Nishiwaki, 2018]
3. matchAll and matchAllDFS for controlling the order of pattern-match results
4. Builtin patterns
Our PMOP language (Egison)
14
Let us see how these features are achieved in Egison:
1. Non-linear pattern matching with multiple results [Egi and Nishiwaki,
2018]
2. Ad-hoc polymorphism of patterns by matchers [Egi and Nishiwaki, 2018]
3. matchAll and matchAllDFS for controlling the order of pattern-match results
4. Builtin patterns
Non-linear pattern matching with multiple results
15
Value patterns (#expr) allow us to refer the value bound to the pattern
variables appear in the left side of the pattern.
• A pattern that matches the elements of the target pair are identical:
match (2, 2) as (integer, integer) with
| ($x, #x) -> x
-- 2
match (2, 1) as (integer, integer) with
| ($x, #x) -> x
-- Error: pattern does not match
Non-linear pattern matching with multiple results
16
The combination of matchAll and non-linear patterns is very powerful!
• Example: A pattern that matches twin primes in the infinite list of prime
numbers:
take 6 (matchAll primes as list integer with
| _ ++ $p :: #(p + 2) :: _ -> (p, p + 2))
-- [(3, 5), (5, 7), (11, 13), (17, 19), (29, 31), (41, 43)]
Our PMOP language (Egison)
17
Let us see how these features are achieved in Egison:
1. Non-linear pattern matching with multiple results [Egi and Nishiwaki, 2018]
2.Ad-hoc polymorphism of patterns by matchers [Egi and Nishiwaki, 2018]
3. matchAll and matchAllDFS for controlling the order of pattern-match results
4. Builtin patterns
Ad-hoc polymorphism of patterns by matchers
18
The cons pattern (::) behaves differently for each matcher:
matchAll [1, 2, 3] as list integer with
| $x :: $xs -> (x, xs)
-- [(1, [2, 3])]
matchAll [1, 2, 3] as multiset integer with
| $x :: $xs -> (x, xs)
-- [(1, [2, 3]), (2, [1, 3]), (3, [1, 2])]
matchAll [1, 2, 3] as set integer with
| $x :: $xs -> (x, xs)
-- [(1, [1, 2, 3]), (2, [1, 2, 3]), (3, [1, 2, 3])]
Ad-hoc polymorphism of patterns by matchers
19
The value pattern is also polymorphic:
matchAll [1, 2, 3] as list integer with
| #[2, 1, 3] -> "Matched"
-- []
matchAll [1, 2, 3] as multiset integer with
| #[2, 1, 3] -> "Matched"
-- ["Matched"]
Our PMOP language (Egison)
20
Let us see how these features are achieved in Egison:
1. Non-linear pattern matching with multiple results [Egi and Nishiwaki, 2018]
2. Ad-hoc polymorphism of patterns by matchers [Egi and Nishiwaki, 2018]
3. matchAll and matchAllDFS for controlling the order of patter-match
results
4. Builtin patterns
matchAll and matchAllDFS control the order of pattern-match results
21
matchAll traverses the search tree in the breadth-first order:
take 6 (matchAll [1..] as set something with
| $x :: $y :: _ -> (x, y))
-- [(1, 1), (1, 2), (2, 1), (1, 3), (2, 2), (3, 1)]
matchAllDFS traverses the search tree in the depth-first order:
take 6 (matchAllDFS [1..] as set something with
| $x :: $y :: _ -> (x, y))
-- [(1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (1, 6)]
matchAll enumerates infinitely many results
22
matchAll enumerates infinitely many pattern-match results:
take 6 (matchAll primes as list integer with
| _ ++ $p :: _ ++ #(p + 6) :: _ -> (p, p + 6))
-- [(5, 11), (7, 13), (11, 17), (13, 19), (17, 23), (23, 29)]
matchAllDFS sometimes cannot enumerate all the results:
take 6 (matchAllDFS primes as list integer with
| _ ++ $p :: _ ++ #(p + 6) :: _ -> (p, p + 6))
-- infinite loop
Our PMOP language (Egison)
23
Let us see how these features are achieved in Egison:
1. Non-linear pattern matching with multiple results [Egi and Nishiwaki, 2018]
2. Ad-hoc polymorphism of patterns by matchers [Egi and Nishiwaki, 2018]
3. matchAll and matchAllDFS for controlling the order of pattern-match results
4.Builtin patterns
Builtin patterns: not-patterns
24
Not-patterns (!pat) match if the pattern (pat) fails to match:
• A pattern that matches when the elements of the target pair are not
identical:
match (2, 2) as (integer, integer) with
| ($x, !#x) -> x
-- Error: pattern does not match
match (2, 1) as (integer, integer) with
| ($x, !#x) -> x
-- 2
Our language supports pattern variables with indices:
matchAllDFS [1, 2, 3] as set something with
| $x_1 :: $x_2 :: _ -> [x_1, x_2]
-- [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]]
The above pattern can be generalized using loop patterns:
matchAllDFS [1, 2, 3] as set something with
| loop $i
(1, n)
($x_i :: ...)
_
-> map (i -> x_i) [1..n]
Builtin patterns: loop patterns for representing repetitions
25
-- index variable
-- index range
-- repeated pattern
-- final pattern
... in a repeated pattern is
expanded to the repeated
pattern or final pattern
incrementing the index.
$x1 :: $x2 :: ... :: $xn :: _
$x1 :: $x2 :: _
More builtin patterns
26
In the paper, we show more builtin patterns: and-patterns, or-patterns,
and sequential patterns (control the order of pattern-match process).
27
Part 1. Motivation
Part 2. Features of our PMOP language
Part 3. PMOP design patterns
Part 4. PMOP in action
PMOP design patterns
28
Join-cons patterns for lists
Enumerate combinations of
elements
Cons patterns for multisets
Enumerate permutations of
elements
Tuple patterns for comparison Compare multiple data
Loop patterns
Describe repetitions inside
patterns
PMOP design patterns
29
Join-cons patterns for lists
Enumerate combinations of
elements
Cons patterns for multisets
Enumerate permutations of
elements
Tuple patterns for comparison Compare multiple data
Loop patterns
Describe repetitions inside
patterns
Join-cons patterns for lists
30
map f xs := matchAll xs as list something with
| _ ++ $x :: _ -> f x
elem x xs := match xs as list eq with
| _ ++ $x :: _ -> True
| _ -> False
elem 2 [1, 2, 3] -- True
elem 4 [1, 2, 3] -- False
delete x xs := match xs as list eq with
| $hs ++ $x :: $ts -> hs ++ ts
| _ -> xs
delete 2 [1, 2, 3] -- [1, 3]
delete 4 [1, 2, 3] -- [1, 2, 3]
Nested join-cons patterns for lists
31
concat xss := matchAllDFS xss as list (list something) with
| (_ ++ (_ ++ $x :: _) :: _) -> x
concat [[1, 2], [3], [], [4, 5]] -- [1, 2, 3, 4, 5]
unique xs := matchAllDFS xs as list eq with
-- The pattern says "x does not appear after $x".
| _ ++ $x :: !(_ ++ #x :: _) -> x
unique [1, 2, 3, 2, 4]
-- [1, 3, 2, 4] ($x matches the last appearance of an element)
PMOP design patterns
32
Join-cons patterns for lists
Enumerate combinations of
elements
Cons patterns for multisets
Enumerate permutations of
elements
Tuple patterns for comparison Compare multiple data
Loop patterns
Describe repetitions inside
patterns
Cons patterns for multisets
33
• Join-cons patterns enumerate combinations of elements:
matchAllDFS [1, 2, 3] as list something with
| _ ++ $x :: _ ++ $y:: _ -> (x, y)
-- [(1, 2), (1, 3), (2, 3)]
• Cons patterns for multisets enumerate permutations of elements:
matchAllDFS [1, 2, 3] as multiset something with
| $x :: $y:: _ -> (x, y)
-- [(1, 2), (1, 3), (2, 1), (2, 3), (3, 1), (3, 2)]
Cons patterns for multisets are often used for describing mathematical
algorithms.
We show an example in Part 4.
PMOP design patterns
34
Join-cons patterns for lists
Enumerate combinations of
elements
Cons patterns for multisets
Enumerate permutations of
elements
Tuple patterns for comparison Compare multiple data
Loop patterns
Describe repetitions inside
patterns
Tuple patterns for comparing multiple data
35
intersect xs ys := matchAll (xs, ys) as (set eq, set eq) with
| ($x :: _, #x :: _) -> x
intersect [1, 2, 3, 4] [2, 4, 5] -- [2, 4]
difference xs ys := matchAll (xs, ys) as (set eq, set eq) with
| ($x :: _, !(#x :: _)) -> x
difference [1, 2, 3, 4] [2, 4, 5] -- [1, 3]
$x matches with a element that
appears in both lists.
$x matches with a element that
appears in xs, but not in ys.
PMOP design patterns
36
Join-cons patterns for lists
Enumerate combinations of
elements
Cons patterns for multisets
Enumerate permutations of
elements
Tuple patterns for comparison Compare multiple data
Loop patterns
Describe repetitions inside
patterns
Builtin patterns: indexed variables and loop patterns
37
Loop patterns are often used for pattern matching graphs and trees.
A pattern that enumerates all routes from Porto that visit all cities exactly
once and return to Porto:
trips :=
let n := length graphData in
matchAll graphData as graph with
| (#"Porto", (($s_1,$p_1) : _)) ::
loop $i (2, n - 1)
((#s_(i - 1), ($s_i, $p_i) :: _) :: ...)
((#s_(n - 1), (#"Porto" & $s_n, $p_n) :: _) :: [])
-> sum (map (i -> p_i) [1..n]), map (i -> s_i) [1..n]
38
Part 1. Motivation
Part 2. Features of our PMOP language
Part 3. PMOP design patterns
Part 4. PMOP in action
PMOP distinguishes two kinds of computations
39
PMOP allows programmers to focus on writing the essential parts of an
algorithm by distinguishing two types of computations:
1. Computations that can be implemented in backtracking algorithms
(backtrack-able computations);
2.Computations that are essential for improving the time complexity of an
algorithm for solving a problem (essential computations).
Essential computations
Traditional FP mixes two computations. PMOP distinguishes two computations.
Backtrack-able computations
Backtrack-able computation
Backtrack-able computation
Backtrack-able computation
Backtrack-able computation
Backtrack-able computation
Backtrack-able computation
Essential computation
Essential computation
Essential computation
SAT solver
40
A SAT solver determines whether a given propositional logic formula has
an assignment for which the formula evaluates to true.
Input formulae for SAT solvers are often in conjunctive normal form.
For example, (p ∨ q) ∧ (¬p ∨ r) ∧ (¬p ∨ ¬r) has a solution; p = false, q = true,
and r = true.
We often encode literals (e.g., p, ¬p) with integers (e.g., 1, -1).
In PMOP, we can treat a formula as a multiset of multisets of integers.
(p ∨ q) ∧ (¬p ∨ r) ∧ (¬p ∨ ¬r) [[1, 2], [-1, 3], [-1, -3]]
We see PMOP in action by showing an implementation of a SAT solver.
Davis-Putnum algorithm: two rules for narrowing search space
41
One-literal rule: when the target formula has a clause with a single literal,
we can assign the literal true immediately.
1. (p) ∧ (¬p ∨ r) ∧ (¬p ∨ ¬r) -- assign "p = true" by one-literal rule
2.(r) ∧ (¬r) -- assign "r = true" by one-literal rule
3.() -- unsatisfiable
Pure-literal rule: when a propositional variable appears only positively
(negatively), we can assign the variable true (false) immediately.
1. (p ∨ q) ∧ (¬p ∨ r) ∧ (¬p ∨ ¬r) -- assign "q = true" by pure-literal rule
2.(¬p ∨ r) ∧ (¬p ∨ ¬r) -- assign "p = false" by pure-literal rule
3.true -- satisfiable
let rec dp clauses =
if clauses = [] then true else if mem [] clauses then false else
try dp (one_literal_rule clauses) with Failure _ ->
try dp (pure_literal_rule clauses) with Failure _ ->
dp(resolution_rule clauses);;
let one_literal_rule clauses =
let u = hd (find (fun cl -> length cl = 1) clauses) in
assignTrue u clauses;;
let pure_literal_rule clauses =
let us = unions clauses in
let u = hd (find (u -> mem (negate u) us) us) in
assignTrue u clauses;;
The code is taken from [Harrison, 2009] and modified.
Davis-Putnum algorithm in traditional FP
42
Davis-Putnum algorithm in PMOP
43
dp cnf :=
matchDFS cnf as multiset (multiset integer) with
| [] -> True
| [] :: _ -> False
-- one-literal rule
| ($x :: []) :: _ -> dp (assignTrue x cnf)
-- pure literal rule
| ($x :: _) :: !((#(negate x) :: _) :: _) -> dp (assignTrue x cnf)
-- otherwise
| _ -> dp (resolution cnf)
dp cnf :=
matchDFS cnf as multiset (multiset integer) with
| [] -> True
| [] :: _ -> False
-- one-literal rule
| ($x :: []) :: _ -> dp (assignTrue x cnf)
-- pure literal rule
| ($x :: _) :: !((#(negate x) :: _) :: _) -> dp (assignTrue x cnf)
-- otherwise
| _ -> dp (resolution cnf)
Davis-Putnum algorithm in PMOP
44
We match a formula (cnf) as a multiset of
multisets of integers.
dp cnf :=
matchDFS cnf as multiset (multiset integer) with
| [] -> True
| [] :: _ -> False
-- one-literal rule
| ($x :: []) :: _ -> dp (assignTrue x cnf)
-- pure literal rule
| ($x :: _) :: !((#(negate x) :: _) :: _) -> dp (assignTrue x cnf)
-- otherwise
| _ -> dp (resolution cnf)
Davis-Putnum algorithm in PMOP
45
This pattern matches when cnf has a clause with a single
literal (e. g., (p) ∧ (¬p ∨ r) ∧ (¬p ∨ ¬r)).
dp cnf :=
matchDFS cnf as multiset (multiset integer) with
| [] -> True
| [] :: _ -> False
-- one-literal rule
| ($x :: []) :: _ -> dp (assignTrue x cnf)
-- pure literal rule
| ($x :: _) :: !((#(negate x) :: _) :: _) -> dp (assignTrue x cnf)
-- otherwise
| _ -> dp (resolution cnf)
Davis-Putnum algorithm in PMOP
46
This pattern says that "the negation of literal x does not
appears in cnf" (e. g., q in (p ∨ q) ∧ (¬p ∨ r) ∧ (¬p ∨ ¬r)).
let rec dp clauses =
if clauses = [] then true else if mem [] clauses then false else
try dp (one_literal_rule clauses) with Failure _ ->
try dp (pure_literal_rule clauses) with Failure _ ->
dp(resolution_rule clauses);;
let one_literal_rule clauses =
let u = hd (find (fun cl -> length cl = 1) clauses) in
assignTrue u clauses;;
let pure_literal_rule clauses =
let us = unions clauses in
let u = hd (find (u -> mem (negate u) us) us) in
assignTrue u clauses;;
The code is taken from [Harrison, 2009] and modified.
Davis-Putnum algorithm in traditional FP
47
PMOP confines these parts in patterns.
dp cnf :=
matchDFS cnf as multiset (multiset integer) with
| [] -> True
| [] :: _ -> False
-- one-literal rule
| ($x :: []) :: _ -> dp (assignTrue x cnf)
-- pure literal rule
| ($x :: _) :: !((#(negate x) :: _) :: _) -> dp (assignTrue x cnf)
-- otherwise
| _ -> dp (resolution cnf)
Davis-Putnum algorithm in PMOP
48
dp is the only recursive function in PMOP
49
dp cnf :=
matchDFS cnf as multiset (multiset integer) with
| [] -> True
| [] :: _ -> False
-- one-literal rule
| ($x :: []) :: _ -> dp (assignTrue x cnf)
-- pure literal rule
| ($x :: _) :: !((#(negate x) :: _) :: _) -> dp (assignTrue x cnf)
-- otherwise
| _ -> dp (resolution cnf)
Summary
50
Summary
51
1. We advocated a programming paradigm that confines recursions in
patterns, called pattern-match-oriented programming (PMOP);
• PMOP distinguishes two kinds of computations: backtrack-able
computations and essential computations;
• PMOP derives several non-standard language constructs such as
matchAllDFS, not-patterns, loop patterns, and sequential patterns.
2.We classified PMOP techniques as PMOP design patterns.
• These PMOP programming techniques were found thanks to the
efforts of many Egison programmers over a long time.
Please try Egison!
Hackage: http://hackage.haskell.org/package/egison
GitHub: https://github.com/egison/egison
Egison Website: https://www.egison.org/
Functional Programming in Pattern-Match-Oriented Style

Weitere ähnliche Inhalte

Was ist angesagt?

Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Hashing notes data structures (HASHING AND HASH FUNCTIONS)Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Hashing notes data structures (HASHING AND HASH FUNCTIONS)Kuntal Bhowmick
 
Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0BG Java EE Course
 
Python programming Part -6
Python programming Part -6Python programming Part -6
Python programming Part -6Megha V
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data StructuresSHAKOOR AB
 
18 hashing
18 hashing18 hashing
18 hashingdeonnash
 
Data types in python
Data types in pythonData types in python
Data types in pythonRaginiJain21
 
High-Performance Haskell
High-Performance HaskellHigh-Performance Haskell
High-Performance HaskellJohan Tibell
 
Monads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy DyagilevMonads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy DyagilevJavaDayUA
 
Data Structure and Algorithms Hashing
Data Structure and Algorithms HashingData Structure and Algorithms Hashing
Data Structure and Algorithms HashingManishPrajapati78
 
Joc live session
Joc live sessionJoc live session
Joc live sessionSIT Tumkur
 
Introduction to haskell
Introduction to haskellIntroduction to haskell
Introduction to haskellLuca Molteni
 
Five Languages in a Moment
Five Languages in a MomentFive Languages in a Moment
Five Languages in a MomentSergio Gil
 
Python advanced 2. regular expression in python
Python advanced 2. regular expression in pythonPython advanced 2. regular expression in python
Python advanced 2. regular expression in pythonJohn(Qiang) Zhang
 
Hashing in datastructure
Hashing in datastructureHashing in datastructure
Hashing in datastructurerajshreemuthiah
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskellgoncharenko
 

Was ist angesagt? (20)

Ds 8
Ds 8Ds 8
Ds 8
 
Hashing
HashingHashing
Hashing
 
Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Hashing notes data structures (HASHING AND HASH FUNCTIONS)Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Hashing notes data structures (HASHING AND HASH FUNCTIONS)
 
Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0
 
Hashing
HashingHashing
Hashing
 
Python programming Part -6
Python programming Part -6Python programming Part -6
Python programming Part -6
 
Hashing
HashingHashing
Hashing
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data Structures
 
18 hashing
18 hashing18 hashing
18 hashing
 
Python numbers
Python numbersPython numbers
Python numbers
 
Data types in python
Data types in pythonData types in python
Data types in python
 
High-Performance Haskell
High-Performance HaskellHigh-Performance Haskell
High-Performance Haskell
 
Monads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy DyagilevMonads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy Dyagilev
 
Data Structure and Algorithms Hashing
Data Structure and Algorithms HashingData Structure and Algorithms Hashing
Data Structure and Algorithms Hashing
 
Joc live session
Joc live sessionJoc live session
Joc live session
 
Introduction to haskell
Introduction to haskellIntroduction to haskell
Introduction to haskell
 
Five Languages in a Moment
Five Languages in a MomentFive Languages in a Moment
Five Languages in a Moment
 
Python advanced 2. regular expression in python
Python advanced 2. regular expression in pythonPython advanced 2. regular expression in python
Python advanced 2. regular expression in python
 
Hashing in datastructure
Hashing in datastructureHashing in datastructure
Hashing in datastructure
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskell
 

Ähnlich wie Functional Programming in Pattern-Match-Oriented Style

CE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdfCE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdfUmarMustafa13
 
Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03Avelin Huo
 
15 functional programming
15 functional programming15 functional programming
15 functional programmingjigeno
 
15 functional programming
15 functional programming15 functional programming
15 functional programmingjigeno
 
NumPy_Broadcasting Data Science - Python.pptx
NumPy_Broadcasting Data Science - Python.pptxNumPy_Broadcasting Data Science - Python.pptx
NumPy_Broadcasting Data Science - Python.pptxJohnWilliam111370
 
Python programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsPython programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsMegha V
 
Real World Haskell: Lecture 2
Real World Haskell: Lecture 2Real World Haskell: Lecture 2
Real World Haskell: Lecture 2Bryan O'Sullivan
 
Using Language Oriented Programming to Execute Computations on the GPU
Using Language Oriented Programming to Execute Computations on the GPUUsing Language Oriented Programming to Execute Computations on the GPU
Using Language Oriented Programming to Execute Computations on the GPUSkills Matter
 
Cs6660 compiler design may june 2016 Answer Key
Cs6660 compiler design may june 2016 Answer KeyCs6660 compiler design may june 2016 Answer Key
Cs6660 compiler design may june 2016 Answer Keyappasami
 
Cosc 2425 project 2 part 1 implement the following c++ code
Cosc 2425   project 2 part 1 implement the following c++ code Cosc 2425   project 2 part 1 implement the following c++ code
Cosc 2425 project 2 part 1 implement the following c++ code AISHA232980
 
R programming slides
R  programming slidesR  programming slides
R programming slidesPankaj Saini
 
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxINFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxcarliotwaycave
 
Query Optimization - Brandon Latronica
Query Optimization - Brandon LatronicaQuery Optimization - Brandon Latronica
Query Optimization - Brandon Latronica"FENG "GEORGE"" YU
 
CLISP Lab Manual - Dr.J.VijiPriya
CLISP Lab Manual - Dr.J.VijiPriyaCLISP Lab Manual - Dr.J.VijiPriya
CLISP Lab Manual - Dr.J.VijiPriyaVijiPriya Jeyamani
 
Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Kyiv 2017, Day 1
Psychtoolbox (PTB) practical course  by Volodymyr B. Bogdanov, Kyiv 2017, Day 1Psychtoolbox (PTB) practical course  by Volodymyr B. Bogdanov, Kyiv 2017, Day 1
Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Kyiv 2017, Day 1Volodymyr Bogdanov
 

Ähnlich wie Functional Programming in Pattern-Match-Oriented Style (20)

An Intoduction to R
An Intoduction to RAn Intoduction to R
An Intoduction to R
 
CE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdfCE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdf
 
Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03
 
15 functional programming
15 functional programming15 functional programming
15 functional programming
 
15 functional programming
15 functional programming15 functional programming
15 functional programming
 
NumPy_Broadcasting Data Science - Python.pptx
NumPy_Broadcasting Data Science - Python.pptxNumPy_Broadcasting Data Science - Python.pptx
NumPy_Broadcasting Data Science - Python.pptx
 
Python - Lecture 12
Python - Lecture 12Python - Lecture 12
Python - Lecture 12
 
Python programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsPython programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operations
 
Real World Haskell: Lecture 2
Real World Haskell: Lecture 2Real World Haskell: Lecture 2
Real World Haskell: Lecture 2
 
Using Language Oriented Programming to Execute Computations on the GPU
Using Language Oriented Programming to Execute Computations on the GPUUsing Language Oriented Programming to Execute Computations on the GPU
Using Language Oriented Programming to Execute Computations on the GPU
 
Python lecture 05
Python lecture 05Python lecture 05
Python lecture 05
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 
Cs6660 compiler design may june 2016 Answer Key
Cs6660 compiler design may june 2016 Answer KeyCs6660 compiler design may june 2016 Answer Key
Cs6660 compiler design may june 2016 Answer Key
 
Cosc 2425 project 2 part 1 implement the following c++ code
Cosc 2425   project 2 part 1 implement the following c++ code Cosc 2425   project 2 part 1 implement the following c++ code
Cosc 2425 project 2 part 1 implement the following c++ code
 
R programming slides
R  programming slidesR  programming slides
R programming slides
 
R basics
R basicsR basics
R basics
 
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxINFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
 
Query Optimization - Brandon Latronica
Query Optimization - Brandon LatronicaQuery Optimization - Brandon Latronica
Query Optimization - Brandon Latronica
 
CLISP Lab Manual - Dr.J.VijiPriya
CLISP Lab Manual - Dr.J.VijiPriyaCLISP Lab Manual - Dr.J.VijiPriya
CLISP Lab Manual - Dr.J.VijiPriya
 
Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Kyiv 2017, Day 1
Psychtoolbox (PTB) practical course  by Volodymyr B. Bogdanov, Kyiv 2017, Day 1Psychtoolbox (PTB) practical course  by Volodymyr B. Bogdanov, Kyiv 2017, Day 1
Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Kyiv 2017, Day 1
 

Mehr von Rakuten Group, Inc.

コードレビュー改善のためにJenkinsとIntelliJ IDEAのプラグインを自作してみた話
コードレビュー改善のためにJenkinsとIntelliJ IDEAのプラグインを自作してみた話コードレビュー改善のためにJenkinsとIntelliJ IDEAのプラグインを自作してみた話
コードレビュー改善のためにJenkinsとIntelliJ IDEAのプラグインを自作してみた話Rakuten Group, Inc.
 
楽天における安全な秘匿情報管理への道のり
楽天における安全な秘匿情報管理への道のり楽天における安全な秘匿情報管理への道のり
楽天における安全な秘匿情報管理への道のりRakuten Group, Inc.
 
Simple and Effective Knowledge-Driven Query Expansion for QA-Based Product At...
Simple and Effective Knowledge-Driven Query Expansion for QA-Based Product At...Simple and Effective Knowledge-Driven Query Expansion for QA-Based Product At...
Simple and Effective Knowledge-Driven Query Expansion for QA-Based Product At...Rakuten Group, Inc.
 
DataSkillCultureを浸透させる楽天の取り組み
DataSkillCultureを浸透させる楽天の取り組みDataSkillCultureを浸透させる楽天の取り組み
DataSkillCultureを浸透させる楽天の取り組みRakuten Group, Inc.
 
大規模なリアルタイム監視の導入と展開
大規模なリアルタイム監視の導入と展開大規模なリアルタイム監視の導入と展開
大規模なリアルタイム監視の導入と展開Rakuten Group, Inc.
 
楽天における大規模データベースの運用
楽天における大規模データベースの運用楽天における大規模データベースの運用
楽天における大規模データベースの運用Rakuten Group, Inc.
 
楽天サービスを支えるネットワークインフラストラクチャー
楽天サービスを支えるネットワークインフラストラクチャー楽天サービスを支えるネットワークインフラストラクチャー
楽天サービスを支えるネットワークインフラストラクチャーRakuten Group, Inc.
 
楽天の規模とクラウドプラットフォーム統括部の役割
楽天の規模とクラウドプラットフォーム統括部の役割楽天の規模とクラウドプラットフォーム統括部の役割
楽天の規模とクラウドプラットフォーム統括部の役割Rakuten Group, Inc.
 
Rakuten Services and Infrastructure Team.pdf
Rakuten Services and Infrastructure Team.pdfRakuten Services and Infrastructure Team.pdf
Rakuten Services and Infrastructure Team.pdfRakuten Group, Inc.
 
The Data Platform Administration Handling the 100 PB.pdf
The Data Platform Administration Handling the 100 PB.pdfThe Data Platform Administration Handling the 100 PB.pdf
The Data Platform Administration Handling the 100 PB.pdfRakuten Group, Inc.
 
Supporting Internal Customers as Technical Account Managers.pdf
Supporting Internal Customers as Technical Account Managers.pdfSupporting Internal Customers as Technical Account Managers.pdf
Supporting Internal Customers as Technical Account Managers.pdfRakuten Group, Inc.
 
Making Cloud Native CI_CD Services.pdf
Making Cloud Native CI_CD Services.pdfMaking Cloud Native CI_CD Services.pdf
Making Cloud Native CI_CD Services.pdfRakuten Group, Inc.
 
How We Defined Our Own Cloud.pdf
How We Defined Our Own Cloud.pdfHow We Defined Our Own Cloud.pdf
How We Defined Our Own Cloud.pdfRakuten Group, Inc.
 
Travel & Leisure Platform Department's tech info
Travel & Leisure Platform Department's tech infoTravel & Leisure Platform Department's tech info
Travel & Leisure Platform Department's tech infoRakuten Group, Inc.
 
Travel & Leisure Platform Department's tech info
Travel & Leisure Platform Department's tech infoTravel & Leisure Platform Department's tech info
Travel & Leisure Platform Department's tech infoRakuten Group, Inc.
 
Introduction of GORA API Group technology
Introduction of GORA API Group technologyIntroduction of GORA API Group technology
Introduction of GORA API Group technologyRakuten Group, Inc.
 
100PBを越えるデータプラットフォームの実情
100PBを越えるデータプラットフォームの実情100PBを越えるデータプラットフォームの実情
100PBを越えるデータプラットフォームの実情Rakuten Group, Inc.
 
社内エンジニアを支えるテクニカルアカウントマネージャー
社内エンジニアを支えるテクニカルアカウントマネージャー社内エンジニアを支えるテクニカルアカウントマネージャー
社内エンジニアを支えるテクニカルアカウントマネージャーRakuten Group, Inc.
 

Mehr von Rakuten Group, Inc. (20)

コードレビュー改善のためにJenkinsとIntelliJ IDEAのプラグインを自作してみた話
コードレビュー改善のためにJenkinsとIntelliJ IDEAのプラグインを自作してみた話コードレビュー改善のためにJenkinsとIntelliJ IDEAのプラグインを自作してみた話
コードレビュー改善のためにJenkinsとIntelliJ IDEAのプラグインを自作してみた話
 
楽天における安全な秘匿情報管理への道のり
楽天における安全な秘匿情報管理への道のり楽天における安全な秘匿情報管理への道のり
楽天における安全な秘匿情報管理への道のり
 
What Makes Software Green?
What Makes Software Green?What Makes Software Green?
What Makes Software Green?
 
Simple and Effective Knowledge-Driven Query Expansion for QA-Based Product At...
Simple and Effective Knowledge-Driven Query Expansion for QA-Based Product At...Simple and Effective Knowledge-Driven Query Expansion for QA-Based Product At...
Simple and Effective Knowledge-Driven Query Expansion for QA-Based Product At...
 
DataSkillCultureを浸透させる楽天の取り組み
DataSkillCultureを浸透させる楽天の取り組みDataSkillCultureを浸透させる楽天の取り組み
DataSkillCultureを浸透させる楽天の取り組み
 
大規模なリアルタイム監視の導入と展開
大規模なリアルタイム監視の導入と展開大規模なリアルタイム監視の導入と展開
大規模なリアルタイム監視の導入と展開
 
楽天における大規模データベースの運用
楽天における大規模データベースの運用楽天における大規模データベースの運用
楽天における大規模データベースの運用
 
楽天サービスを支えるネットワークインフラストラクチャー
楽天サービスを支えるネットワークインフラストラクチャー楽天サービスを支えるネットワークインフラストラクチャー
楽天サービスを支えるネットワークインフラストラクチャー
 
楽天の規模とクラウドプラットフォーム統括部の役割
楽天の規模とクラウドプラットフォーム統括部の役割楽天の規模とクラウドプラットフォーム統括部の役割
楽天の規模とクラウドプラットフォーム統括部の役割
 
Rakuten Services and Infrastructure Team.pdf
Rakuten Services and Infrastructure Team.pdfRakuten Services and Infrastructure Team.pdf
Rakuten Services and Infrastructure Team.pdf
 
The Data Platform Administration Handling the 100 PB.pdf
The Data Platform Administration Handling the 100 PB.pdfThe Data Platform Administration Handling the 100 PB.pdf
The Data Platform Administration Handling the 100 PB.pdf
 
Supporting Internal Customers as Technical Account Managers.pdf
Supporting Internal Customers as Technical Account Managers.pdfSupporting Internal Customers as Technical Account Managers.pdf
Supporting Internal Customers as Technical Account Managers.pdf
 
Making Cloud Native CI_CD Services.pdf
Making Cloud Native CI_CD Services.pdfMaking Cloud Native CI_CD Services.pdf
Making Cloud Native CI_CD Services.pdf
 
How We Defined Our Own Cloud.pdf
How We Defined Our Own Cloud.pdfHow We Defined Our Own Cloud.pdf
How We Defined Our Own Cloud.pdf
 
Travel & Leisure Platform Department's tech info
Travel & Leisure Platform Department's tech infoTravel & Leisure Platform Department's tech info
Travel & Leisure Platform Department's tech info
 
Travel & Leisure Platform Department's tech info
Travel & Leisure Platform Department's tech infoTravel & Leisure Platform Department's tech info
Travel & Leisure Platform Department's tech info
 
OWASPTop10_Introduction
OWASPTop10_IntroductionOWASPTop10_Introduction
OWASPTop10_Introduction
 
Introduction of GORA API Group technology
Introduction of GORA API Group technologyIntroduction of GORA API Group technology
Introduction of GORA API Group technology
 
100PBを越えるデータプラットフォームの実情
100PBを越えるデータプラットフォームの実情100PBを越えるデータプラットフォームの実情
100PBを越えるデータプラットフォームの実情
 
社内エンジニアを支えるテクニカルアカウントマネージャー
社内エンジニアを支えるテクニカルアカウントマネージャー社内エンジニアを支えるテクニカルアカウントマネージャー
社内エンジニアを支えるテクニカルアカウントマネージャー
 

Kürzlich hochgeladen

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 

Kürzlich hochgeladen (20)

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 

Functional Programming in Pattern-Match-Oriented Style

  • 1. Functional Programming in Pattern- Match-Oriented Programming Style <Programming> 2020 Research Paper Mar 22-26th, 2021 Satoshi Egi (Rakuten Institute of Technology, Rakuten, Inc.) Yuichi Nishiwaki (The University of Tokyo)
  • 3. 3 How do you explain the map function? map (x -> x + 10) [1, 2, 3] -- [11, 12, 13] The map function takes a function and a list, and returns a list of the results of applying the function to all the elements of the list. No one explain like this: The map function takes a function and a list, and returns an empty list if the argument list is empty. Otherwise, it returns a list whose head element is the result of applying the function to the head element of the argument list, and the tail part is the result of applying the map function recursively to the tail part of the argument list. However, the standard functional definition is similar to this explanation: map f [] := [] map f (x :: xs) := f x :: map f xs
  • 4. The mapWithBothSides function 4 Let us consider a variation of map, mapWithBothSides. mapWithBothSides (hs, x, ts -> (hs, x, ts)) [1, 2, 3] -- [([], 1, [2, 3]), ([1], 2, [3])]), ([1, 2], 3, [])] mapWithBothSides (hs, _, ts -> hs ++ ts) [1, 2, 3] -- [[2, 3], [1, 3], [1, 2]]
  • 5. The mapWithBothSides function 5 Functional definition of mapWithBothSides: mapWithBothSides f xs := helper f [] xs where helper f xs [] := [] helper f xs (y :: ys) := f xs y ys :: helper f (xs ++ [y]) ys It is natural to use a helper function for defining mapWithBothSides. Explanation of mapWithBothSides: • takes a function of three arguments and a list, and • returns a list of applying the function for all three-tuples consisting of an initial prefix, the next element, and the remaining suffix.
  • 6. The gap between the explanation and definition 6 The explanations of map and mapWithBothSides are very similar, but the definitions are very different. map f [] := [] map f (x :: xs) := f x :: map f xs mapWithBothSides f xs := helper f [] xs where helper f xs [] := [] helper f xs (y :: ys) := f xs y ys :: helper f (xs ++ [y]) ys Can we fill this cognitive gap between the explanation and definition?
  • 7. Pattern matching fills the gap 7 User-extensible non-linear pattern matching with backtracking [Egi and Nishiwaki, 2018] implemented in the Egison programming language can fill the gap. map f xs := matchAll xs as list something with | _ ++ $x :: _ -> f x mapWithBothSides f xs := matchAll xs as list something with | $hs ++ $x :: $ts -> f hs x ts The join pattern (++) splits a list to an initial prefix and the remaining suffix. The cons pattern (::) decomposes a list to the initial element and the rest. matchAll collects all pattern-match results. list something is a matcher and specifies how to interpret the pattern. $hs ++ $x :: $ts is a pattern that splits the target list into an initial prefix, the next element, and the remaining suffix.
  • 8. Our approach: pattern-match-oriented programming (PMOP) 8 mapWithBothSides f xs = helper f [] xs where helper f xs [] := [] helper f xs (y : : ys) := (f xs y ys) :: (helper f (xs ++ [y]) ys) mapWithBothSides f xs := matchAll xs as list something with | $hs ++ $x :: $ts -> f hs x ts • Our key insight: recursions can be confined in patterns. • In this case, $hs ++ $x :: $ts confines helper. • We call the programming style that confines explicit recursions in patterns, pattern-match-oriented programming (PMOP). • We aim to clarify what is PMOP by showing PMOP examples we found so far. Traditional FP Our approach
  • 9. Organization of this presentation 9 Part 1. Motivation Part 2. Features of our PMOP language Part 3. PMOP design patterns Part 4. PMOP in action
  • 10. 10 Part 1. Motivation Part 2. Features of our PMOP language Part 3. PMOP design patterns Part 4. PMOP in action
  • 11. Our PMOP language (Egison) 11 We demonstrate PMOP with our language Egison. Egison was originally designed for concise description of algorithms with non-free data types such as multisets, graphs, mathematical expressions [Egi and Nishiwaki, 2018]. Egison has achieved this mission by user-extensible non-linear pattern- match facility with backtracking. Free data types Non-free data types Consed lists, Syntax trees, ...etc. Multisets, Sets, Graphs, Mathematical expressions, ...etc.
  • 12. The history of pattern matching 12 [Burstall, 1969] Views [Wadler, 1987] Active patterns [Erwig, 1996] First class patterns [Tullsen, 2000] [Queinnec, 1990] Egison [Egi and Nishiwaki, 2018] non-linear pattern, multiple results user-extensible pattern, polymorphic pattern user-extensible pattern non-linear pattern multiple results multiple results, polymorphic pattern non-linear pattern, polymorphic pattern loop pattern, sequential pattern, ...
  • 13. Our PMOP language (Egison) 13 Let us see how these features are achieved in Egison: 1. Non-linear pattern matching with multiple results [Egi and Nishiwaki, 2018] 2. Ad-hoc polymorphism of patterns by matchers [Egi and Nishiwaki, 2018] 3. matchAll and matchAllDFS for controlling the order of pattern-match results 4. Builtin patterns
  • 14. Our PMOP language (Egison) 14 Let us see how these features are achieved in Egison: 1. Non-linear pattern matching with multiple results [Egi and Nishiwaki, 2018] 2. Ad-hoc polymorphism of patterns by matchers [Egi and Nishiwaki, 2018] 3. matchAll and matchAllDFS for controlling the order of pattern-match results 4. Builtin patterns
  • 15. Non-linear pattern matching with multiple results 15 Value patterns (#expr) allow us to refer the value bound to the pattern variables appear in the left side of the pattern. • A pattern that matches the elements of the target pair are identical: match (2, 2) as (integer, integer) with | ($x, #x) -> x -- 2 match (2, 1) as (integer, integer) with | ($x, #x) -> x -- Error: pattern does not match
  • 16. Non-linear pattern matching with multiple results 16 The combination of matchAll and non-linear patterns is very powerful! • Example: A pattern that matches twin primes in the infinite list of prime numbers: take 6 (matchAll primes as list integer with | _ ++ $p :: #(p + 2) :: _ -> (p, p + 2)) -- [(3, 5), (5, 7), (11, 13), (17, 19), (29, 31), (41, 43)]
  • 17. Our PMOP language (Egison) 17 Let us see how these features are achieved in Egison: 1. Non-linear pattern matching with multiple results [Egi and Nishiwaki, 2018] 2.Ad-hoc polymorphism of patterns by matchers [Egi and Nishiwaki, 2018] 3. matchAll and matchAllDFS for controlling the order of pattern-match results 4. Builtin patterns
  • 18. Ad-hoc polymorphism of patterns by matchers 18 The cons pattern (::) behaves differently for each matcher: matchAll [1, 2, 3] as list integer with | $x :: $xs -> (x, xs) -- [(1, [2, 3])] matchAll [1, 2, 3] as multiset integer with | $x :: $xs -> (x, xs) -- [(1, [2, 3]), (2, [1, 3]), (3, [1, 2])] matchAll [1, 2, 3] as set integer with | $x :: $xs -> (x, xs) -- [(1, [1, 2, 3]), (2, [1, 2, 3]), (3, [1, 2, 3])]
  • 19. Ad-hoc polymorphism of patterns by matchers 19 The value pattern is also polymorphic: matchAll [1, 2, 3] as list integer with | #[2, 1, 3] -> "Matched" -- [] matchAll [1, 2, 3] as multiset integer with | #[2, 1, 3] -> "Matched" -- ["Matched"]
  • 20. Our PMOP language (Egison) 20 Let us see how these features are achieved in Egison: 1. Non-linear pattern matching with multiple results [Egi and Nishiwaki, 2018] 2. Ad-hoc polymorphism of patterns by matchers [Egi and Nishiwaki, 2018] 3. matchAll and matchAllDFS for controlling the order of patter-match results 4. Builtin patterns
  • 21. matchAll and matchAllDFS control the order of pattern-match results 21 matchAll traverses the search tree in the breadth-first order: take 6 (matchAll [1..] as set something with | $x :: $y :: _ -> (x, y)) -- [(1, 1), (1, 2), (2, 1), (1, 3), (2, 2), (3, 1)] matchAllDFS traverses the search tree in the depth-first order: take 6 (matchAllDFS [1..] as set something with | $x :: $y :: _ -> (x, y)) -- [(1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (1, 6)]
  • 22. matchAll enumerates infinitely many results 22 matchAll enumerates infinitely many pattern-match results: take 6 (matchAll primes as list integer with | _ ++ $p :: _ ++ #(p + 6) :: _ -> (p, p + 6)) -- [(5, 11), (7, 13), (11, 17), (13, 19), (17, 23), (23, 29)] matchAllDFS sometimes cannot enumerate all the results: take 6 (matchAllDFS primes as list integer with | _ ++ $p :: _ ++ #(p + 6) :: _ -> (p, p + 6)) -- infinite loop
  • 23. Our PMOP language (Egison) 23 Let us see how these features are achieved in Egison: 1. Non-linear pattern matching with multiple results [Egi and Nishiwaki, 2018] 2. Ad-hoc polymorphism of patterns by matchers [Egi and Nishiwaki, 2018] 3. matchAll and matchAllDFS for controlling the order of pattern-match results 4.Builtin patterns
  • 24. Builtin patterns: not-patterns 24 Not-patterns (!pat) match if the pattern (pat) fails to match: • A pattern that matches when the elements of the target pair are not identical: match (2, 2) as (integer, integer) with | ($x, !#x) -> x -- Error: pattern does not match match (2, 1) as (integer, integer) with | ($x, !#x) -> x -- 2
  • 25. Our language supports pattern variables with indices: matchAllDFS [1, 2, 3] as set something with | $x_1 :: $x_2 :: _ -> [x_1, x_2] -- [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]] The above pattern can be generalized using loop patterns: matchAllDFS [1, 2, 3] as set something with | loop $i (1, n) ($x_i :: ...) _ -> map (i -> x_i) [1..n] Builtin patterns: loop patterns for representing repetitions 25 -- index variable -- index range -- repeated pattern -- final pattern ... in a repeated pattern is expanded to the repeated pattern or final pattern incrementing the index. $x1 :: $x2 :: ... :: $xn :: _ $x1 :: $x2 :: _
  • 26. More builtin patterns 26 In the paper, we show more builtin patterns: and-patterns, or-patterns, and sequential patterns (control the order of pattern-match process).
  • 27. 27 Part 1. Motivation Part 2. Features of our PMOP language Part 3. PMOP design patterns Part 4. PMOP in action
  • 28. PMOP design patterns 28 Join-cons patterns for lists Enumerate combinations of elements Cons patterns for multisets Enumerate permutations of elements Tuple patterns for comparison Compare multiple data Loop patterns Describe repetitions inside patterns
  • 29. PMOP design patterns 29 Join-cons patterns for lists Enumerate combinations of elements Cons patterns for multisets Enumerate permutations of elements Tuple patterns for comparison Compare multiple data Loop patterns Describe repetitions inside patterns
  • 30. Join-cons patterns for lists 30 map f xs := matchAll xs as list something with | _ ++ $x :: _ -> f x elem x xs := match xs as list eq with | _ ++ $x :: _ -> True | _ -> False elem 2 [1, 2, 3] -- True elem 4 [1, 2, 3] -- False delete x xs := match xs as list eq with | $hs ++ $x :: $ts -> hs ++ ts | _ -> xs delete 2 [1, 2, 3] -- [1, 3] delete 4 [1, 2, 3] -- [1, 2, 3]
  • 31. Nested join-cons patterns for lists 31 concat xss := matchAllDFS xss as list (list something) with | (_ ++ (_ ++ $x :: _) :: _) -> x concat [[1, 2], [3], [], [4, 5]] -- [1, 2, 3, 4, 5] unique xs := matchAllDFS xs as list eq with -- The pattern says "x does not appear after $x". | _ ++ $x :: !(_ ++ #x :: _) -> x unique [1, 2, 3, 2, 4] -- [1, 3, 2, 4] ($x matches the last appearance of an element)
  • 32. PMOP design patterns 32 Join-cons patterns for lists Enumerate combinations of elements Cons patterns for multisets Enumerate permutations of elements Tuple patterns for comparison Compare multiple data Loop patterns Describe repetitions inside patterns
  • 33. Cons patterns for multisets 33 • Join-cons patterns enumerate combinations of elements: matchAllDFS [1, 2, 3] as list something with | _ ++ $x :: _ ++ $y:: _ -> (x, y) -- [(1, 2), (1, 3), (2, 3)] • Cons patterns for multisets enumerate permutations of elements: matchAllDFS [1, 2, 3] as multiset something with | $x :: $y:: _ -> (x, y) -- [(1, 2), (1, 3), (2, 1), (2, 3), (3, 1), (3, 2)] Cons patterns for multisets are often used for describing mathematical algorithms. We show an example in Part 4.
  • 34. PMOP design patterns 34 Join-cons patterns for lists Enumerate combinations of elements Cons patterns for multisets Enumerate permutations of elements Tuple patterns for comparison Compare multiple data Loop patterns Describe repetitions inside patterns
  • 35. Tuple patterns for comparing multiple data 35 intersect xs ys := matchAll (xs, ys) as (set eq, set eq) with | ($x :: _, #x :: _) -> x intersect [1, 2, 3, 4] [2, 4, 5] -- [2, 4] difference xs ys := matchAll (xs, ys) as (set eq, set eq) with | ($x :: _, !(#x :: _)) -> x difference [1, 2, 3, 4] [2, 4, 5] -- [1, 3] $x matches with a element that appears in both lists. $x matches with a element that appears in xs, but not in ys.
  • 36. PMOP design patterns 36 Join-cons patterns for lists Enumerate combinations of elements Cons patterns for multisets Enumerate permutations of elements Tuple patterns for comparison Compare multiple data Loop patterns Describe repetitions inside patterns
  • 37. Builtin patterns: indexed variables and loop patterns 37 Loop patterns are often used for pattern matching graphs and trees. A pattern that enumerates all routes from Porto that visit all cities exactly once and return to Porto: trips := let n := length graphData in matchAll graphData as graph with | (#"Porto", (($s_1,$p_1) : _)) :: loop $i (2, n - 1) ((#s_(i - 1), ($s_i, $p_i) :: _) :: ...) ((#s_(n - 1), (#"Porto" & $s_n, $p_n) :: _) :: []) -> sum (map (i -> p_i) [1..n]), map (i -> s_i) [1..n]
  • 38. 38 Part 1. Motivation Part 2. Features of our PMOP language Part 3. PMOP design patterns Part 4. PMOP in action
  • 39. PMOP distinguishes two kinds of computations 39 PMOP allows programmers to focus on writing the essential parts of an algorithm by distinguishing two types of computations: 1. Computations that can be implemented in backtracking algorithms (backtrack-able computations); 2.Computations that are essential for improving the time complexity of an algorithm for solving a problem (essential computations). Essential computations Traditional FP mixes two computations. PMOP distinguishes two computations. Backtrack-able computations Backtrack-able computation Backtrack-able computation Backtrack-able computation Backtrack-able computation Backtrack-able computation Backtrack-able computation Essential computation Essential computation Essential computation
  • 40. SAT solver 40 A SAT solver determines whether a given propositional logic formula has an assignment for which the formula evaluates to true. Input formulae for SAT solvers are often in conjunctive normal form. For example, (p ∨ q) ∧ (¬p ∨ r) ∧ (¬p ∨ ¬r) has a solution; p = false, q = true, and r = true. We often encode literals (e.g., p, ¬p) with integers (e.g., 1, -1). In PMOP, we can treat a formula as a multiset of multisets of integers. (p ∨ q) ∧ (¬p ∨ r) ∧ (¬p ∨ ¬r) [[1, 2], [-1, 3], [-1, -3]] We see PMOP in action by showing an implementation of a SAT solver.
  • 41. Davis-Putnum algorithm: two rules for narrowing search space 41 One-literal rule: when the target formula has a clause with a single literal, we can assign the literal true immediately. 1. (p) ∧ (¬p ∨ r) ∧ (¬p ∨ ¬r) -- assign "p = true" by one-literal rule 2.(r) ∧ (¬r) -- assign "r = true" by one-literal rule 3.() -- unsatisfiable Pure-literal rule: when a propositional variable appears only positively (negatively), we can assign the variable true (false) immediately. 1. (p ∨ q) ∧ (¬p ∨ r) ∧ (¬p ∨ ¬r) -- assign "q = true" by pure-literal rule 2.(¬p ∨ r) ∧ (¬p ∨ ¬r) -- assign "p = false" by pure-literal rule 3.true -- satisfiable
  • 42. let rec dp clauses = if clauses = [] then true else if mem [] clauses then false else try dp (one_literal_rule clauses) with Failure _ -> try dp (pure_literal_rule clauses) with Failure _ -> dp(resolution_rule clauses);; let one_literal_rule clauses = let u = hd (find (fun cl -> length cl = 1) clauses) in assignTrue u clauses;; let pure_literal_rule clauses = let us = unions clauses in let u = hd (find (u -> mem (negate u) us) us) in assignTrue u clauses;; The code is taken from [Harrison, 2009] and modified. Davis-Putnum algorithm in traditional FP 42
  • 43. Davis-Putnum algorithm in PMOP 43 dp cnf := matchDFS cnf as multiset (multiset integer) with | [] -> True | [] :: _ -> False -- one-literal rule | ($x :: []) :: _ -> dp (assignTrue x cnf) -- pure literal rule | ($x :: _) :: !((#(negate x) :: _) :: _) -> dp (assignTrue x cnf) -- otherwise | _ -> dp (resolution cnf)
  • 44. dp cnf := matchDFS cnf as multiset (multiset integer) with | [] -> True | [] :: _ -> False -- one-literal rule | ($x :: []) :: _ -> dp (assignTrue x cnf) -- pure literal rule | ($x :: _) :: !((#(negate x) :: _) :: _) -> dp (assignTrue x cnf) -- otherwise | _ -> dp (resolution cnf) Davis-Putnum algorithm in PMOP 44 We match a formula (cnf) as a multiset of multisets of integers.
  • 45. dp cnf := matchDFS cnf as multiset (multiset integer) with | [] -> True | [] :: _ -> False -- one-literal rule | ($x :: []) :: _ -> dp (assignTrue x cnf) -- pure literal rule | ($x :: _) :: !((#(negate x) :: _) :: _) -> dp (assignTrue x cnf) -- otherwise | _ -> dp (resolution cnf) Davis-Putnum algorithm in PMOP 45 This pattern matches when cnf has a clause with a single literal (e. g., (p) ∧ (¬p ∨ r) ∧ (¬p ∨ ¬r)).
  • 46. dp cnf := matchDFS cnf as multiset (multiset integer) with | [] -> True | [] :: _ -> False -- one-literal rule | ($x :: []) :: _ -> dp (assignTrue x cnf) -- pure literal rule | ($x :: _) :: !((#(negate x) :: _) :: _) -> dp (assignTrue x cnf) -- otherwise | _ -> dp (resolution cnf) Davis-Putnum algorithm in PMOP 46 This pattern says that "the negation of literal x does not appears in cnf" (e. g., q in (p ∨ q) ∧ (¬p ∨ r) ∧ (¬p ∨ ¬r)).
  • 47. let rec dp clauses = if clauses = [] then true else if mem [] clauses then false else try dp (one_literal_rule clauses) with Failure _ -> try dp (pure_literal_rule clauses) with Failure _ -> dp(resolution_rule clauses);; let one_literal_rule clauses = let u = hd (find (fun cl -> length cl = 1) clauses) in assignTrue u clauses;; let pure_literal_rule clauses = let us = unions clauses in let u = hd (find (u -> mem (negate u) us) us) in assignTrue u clauses;; The code is taken from [Harrison, 2009] and modified. Davis-Putnum algorithm in traditional FP 47 PMOP confines these parts in patterns.
  • 48. dp cnf := matchDFS cnf as multiset (multiset integer) with | [] -> True | [] :: _ -> False -- one-literal rule | ($x :: []) :: _ -> dp (assignTrue x cnf) -- pure literal rule | ($x :: _) :: !((#(negate x) :: _) :: _) -> dp (assignTrue x cnf) -- otherwise | _ -> dp (resolution cnf) Davis-Putnum algorithm in PMOP 48
  • 49. dp is the only recursive function in PMOP 49 dp cnf := matchDFS cnf as multiset (multiset integer) with | [] -> True | [] :: _ -> False -- one-literal rule | ($x :: []) :: _ -> dp (assignTrue x cnf) -- pure literal rule | ($x :: _) :: !((#(negate x) :: _) :: _) -> dp (assignTrue x cnf) -- otherwise | _ -> dp (resolution cnf)
  • 51. Summary 51 1. We advocated a programming paradigm that confines recursions in patterns, called pattern-match-oriented programming (PMOP); • PMOP distinguishes two kinds of computations: backtrack-able computations and essential computations; • PMOP derives several non-standard language constructs such as matchAllDFS, not-patterns, loop patterns, and sequential patterns. 2.We classified PMOP techniques as PMOP design patterns. • These PMOP programming techniques were found thanks to the efforts of many Egison programmers over a long time. Please try Egison! Hackage: http://hackage.haskell.org/package/egison GitHub: https://github.com/egison/egison Egison Website: https://www.egison.org/