Selection sort works by repeatedly finding the minimum element from the unsorted section of an array and placing it at the beginning. It maintains two subarrays - the sorted section and the unsorted section. In each iteration, the minimum element from the unsorted section is selected and swapped with the element in the sorted section. The algorithm has a runtime of (n2) and is an in-place sorting algorithm. An example is provided to illustrate the steps of selection sort on a sample array.
The document discusses dictionaries in Python. It explains that a dictionary is a collection of unordered key-value pairs where keys must be unique. Keys can be strings, numbers, or tuples, while values can be any data type. Dictionaries allow accessing values using keys. Common dictionary operations include adding/updating items, checking if a key exists, getting values, and looping through keys and key-value pairs. The document also provides examples of using dictionaries to count word frequencies in a text file by parsing and removing punctuation.
The document discusses various sorting algorithms including selection sort, insertion sort, merge sort, quick sort, heap sort, and external sort. It provides descriptions of each algorithm, examples of how they work, and discusses implementation in languages like C++. Key steps and properties of each algorithm are outlined. Implementation details like pseudocode and functions are also described.
This document provides an overview of functional programming with Haskell. It discusses key concepts of functional programming like immutable data structures and pure functions. It introduces Haskell types including basic types, tuples, lists, data types, and type classes. It covers Haskell functions like pattern matching, guards, and higher order functions. It also discusses Haskell concepts like laziness, currying, and polymorphism. Finally, it provides an introduction to monads in Haskell and discusses Haskell tools, frameworks, and performance.
This document discusses domain modeling in a functional world based on the speaker's real life experiences. The speaker covers topics like immutability and algebraic data types, updating domain models functionally using lenses, type classes for domain modeling, and managing states functionally. The speaker advocates for isolating pure domain logic from side effects to make the logic easier to test, reason about, and parallelize. Functional composition is emphasized as a way to build complex abstractions from simpler ones.
Exploring ZIO Prelude: The game changer for typeclasses in ScalaJorge V叩squez
油
The document discusses ZIO Prelude, a Scala library that provides typeclasses. It motivates ZIO Prelude by explaining limitations of Scalaz in Scala compared to Haskell. It then provides an overview and tour of capabilities in ZIO Prelude, including validating data with Validation to accumulate all errors, combining nested data structures by summing stats, and executing pure computations. The document uses examples to demonstrate how ZIO Prelude provides a more Scala-centric approach to functional programming compared to porting Haskell concepts.
Monoids - Part 1 - with examples using Scalaz and CatsPhilip Schwarz
油
A monoid is an algebraic structure consisting of a set and a binary operation that is associative and has an identity element. Some key properties of monoids include:
1) A monoid consists of a type A, a binary operation op that combines two values of type A, and a zero value that acts as an identity.
2) The binary operation must be associative, meaning op(op(x,y),z) = op(x,op(y,z)).
3) The zero value must satisfy the identity laws: op(x, zero) = x and op(zero, x) = x.
4) Common examples of monoids include string concatenation
Point free or die - tacit programming in Haskell and beyondPhilip Schwarz
油
I really liked Amar Shah's talk on point-free style as a tool for producing tacit code which communicates better because it is quiet and so easier to understand. https://www.youtube.com/watch?v=seVSlKazsNk
This slide deck is my effort to capture the content of the talk in a way that can aid its consumption, digestion and retention.
Download for better quality.
The document presents an overview of selection sort, including its definition, algorithm, example, advantages, and disadvantages. Selection sort works by iteratively finding the minimum element in an unsorted sublist and exchanging it with the first element. It has a time complexity of O(n2) but performs well on small lists since it is an in-place sorting algorithm with minimal additional storage requirements. However, it is not efficient for huge datasets due to its quadratic time complexity.
This document discusses Python modules, classes, inheritance, and properties. Some key points:
- Modules allow the organization of Python code into reusable libraries by saving code in files with a .py extension. Modules can contain functions, variables, and be imported into other code.
- Classes are templates that define the properties and methods common to all objects of a certain kind. The __init__() method initializes new objects. Inheritance allows child classes to inherit properties and methods from parent classes.
- Properties provide a way to control access to class attributes, allowing them to be accessed like attributes while hiding the implementation details behind getter and setter methods.
This document provides an overview of selection sort, including its objectives, previous knowledge required, algorithm, program, animation, applications, and advantages/disadvantages. Selection sort works by iterating through an array and swapping the smallest remaining element into the sorted portion of the array. It is useful for sorting small arrays or when memory is limited, but performs more slowly as the number of elements increases compared to other sorting algorithms.
The document discusses various types of operators in PHP including arithmetic, assignment, comparison, increment/decrement, logical, string, and array operators. It provides examples of common operators like addition, subtraction, equality checking, concatenation and describes what each operator does.
Quicksort is a divide and conquer algorithm that works by picking an element as a pivot and partitioning the array around it. It recursively sorts elements before and after the pivot. The average runtime is O(n log n) but it can be O(n^2) in the worst case if the pivot selection is poor. The algorithm involves picking a pivot element, partitioning the array around it, and then recursively sorting the subarrays.
Monad as functor with pair of natural transformationsPhilip Schwarz
油
Explains why a Monad is a functor with a pair of natural transformations (plus associativity and identity laws). It then explores this by looking at an example, with code in Scala.
Inspired and based on videos/publications by Bartosz Milewski, R炭nar Bjarnason and Rob Norris.
Download for better quality.
Selection sort works by repeatedly finding the minimum element from the unsorted section of an array and placing it at the beginning. It maintains two subarrays - the sorted section and the unsorted section. In each iteration, the minimum element from the unsorted section is selected and swapped with the element in the sorted section. The algorithm has a runtime of (n2) and is an in-place sorting algorithm. An example is provided to illustrate the steps of selection sort on a sample array.
The document discusses dictionaries in Python. It explains that a dictionary is a collection of unordered key-value pairs where keys must be unique. Keys can be strings, numbers, or tuples, while values can be any data type. Dictionaries allow accessing values using keys. Common dictionary operations include adding/updating items, checking if a key exists, getting values, and looping through keys and key-value pairs. The document also provides examples of using dictionaries to count word frequencies in a text file by parsing and removing punctuation.
The document discusses various sorting algorithms including selection sort, insertion sort, merge sort, quick sort, heap sort, and external sort. It provides descriptions of each algorithm, examples of how they work, and discusses implementation in languages like C++. Key steps and properties of each algorithm are outlined. Implementation details like pseudocode and functions are also described.
This document provides an overview of functional programming with Haskell. It discusses key concepts of functional programming like immutable data structures and pure functions. It introduces Haskell types including basic types, tuples, lists, data types, and type classes. It covers Haskell functions like pattern matching, guards, and higher order functions. It also discusses Haskell concepts like laziness, currying, and polymorphism. Finally, it provides an introduction to monads in Haskell and discusses Haskell tools, frameworks, and performance.
This document discusses domain modeling in a functional world based on the speaker's real life experiences. The speaker covers topics like immutability and algebraic data types, updating domain models functionally using lenses, type classes for domain modeling, and managing states functionally. The speaker advocates for isolating pure domain logic from side effects to make the logic easier to test, reason about, and parallelize. Functional composition is emphasized as a way to build complex abstractions from simpler ones.
Exploring ZIO Prelude: The game changer for typeclasses in ScalaJorge V叩squez
油
The document discusses ZIO Prelude, a Scala library that provides typeclasses. It motivates ZIO Prelude by explaining limitations of Scalaz in Scala compared to Haskell. It then provides an overview and tour of capabilities in ZIO Prelude, including validating data with Validation to accumulate all errors, combining nested data structures by summing stats, and executing pure computations. The document uses examples to demonstrate how ZIO Prelude provides a more Scala-centric approach to functional programming compared to porting Haskell concepts.
Monoids - Part 1 - with examples using Scalaz and CatsPhilip Schwarz
油
A monoid is an algebraic structure consisting of a set and a binary operation that is associative and has an identity element. Some key properties of monoids include:
1) A monoid consists of a type A, a binary operation op that combines two values of type A, and a zero value that acts as an identity.
2) The binary operation must be associative, meaning op(op(x,y),z) = op(x,op(y,z)).
3) The zero value must satisfy the identity laws: op(x, zero) = x and op(zero, x) = x.
4) Common examples of monoids include string concatenation
Point free or die - tacit programming in Haskell and beyondPhilip Schwarz
油
I really liked Amar Shah's talk on point-free style as a tool for producing tacit code which communicates better because it is quiet and so easier to understand. https://www.youtube.com/watch?v=seVSlKazsNk
This slide deck is my effort to capture the content of the talk in a way that can aid its consumption, digestion and retention.
Download for better quality.
The document presents an overview of selection sort, including its definition, algorithm, example, advantages, and disadvantages. Selection sort works by iteratively finding the minimum element in an unsorted sublist and exchanging it with the first element. It has a time complexity of O(n2) but performs well on small lists since it is an in-place sorting algorithm with minimal additional storage requirements. However, it is not efficient for huge datasets due to its quadratic time complexity.
This document discusses Python modules, classes, inheritance, and properties. Some key points:
- Modules allow the organization of Python code into reusable libraries by saving code in files with a .py extension. Modules can contain functions, variables, and be imported into other code.
- Classes are templates that define the properties and methods common to all objects of a certain kind. The __init__() method initializes new objects. Inheritance allows child classes to inherit properties and methods from parent classes.
- Properties provide a way to control access to class attributes, allowing them to be accessed like attributes while hiding the implementation details behind getter and setter methods.
This document provides an overview of selection sort, including its objectives, previous knowledge required, algorithm, program, animation, applications, and advantages/disadvantages. Selection sort works by iterating through an array and swapping the smallest remaining element into the sorted portion of the array. It is useful for sorting small arrays or when memory is limited, but performs more slowly as the number of elements increases compared to other sorting algorithms.
The document discusses various types of operators in PHP including arithmetic, assignment, comparison, increment/decrement, logical, string, and array operators. It provides examples of common operators like addition, subtraction, equality checking, concatenation and describes what each operator does.
Quicksort is a divide and conquer algorithm that works by picking an element as a pivot and partitioning the array around it. It recursively sorts elements before and after the pivot. The average runtime is O(n log n) but it can be O(n^2) in the worst case if the pivot selection is poor. The algorithm involves picking a pivot element, partitioning the array around it, and then recursively sorting the subarrays.
Monad as functor with pair of natural transformationsPhilip Schwarz
油
Explains why a Monad is a functor with a pair of natural transformations (plus associativity and identity laws). It then explores this by looking at an example, with code in Scala.
Inspired and based on videos/publications by Bartosz Milewski, R炭nar Bjarnason and Rob Norris.
Download for better quality.
2. Pattern matching
襷れ広 襯 襷 蟲ロ 螳ロ 蟲覓語. 襷れ広 企 一危郁
螳語 伎 覈螻, 一危郁 蠏 一危郁 企 伎 襷豢 覿企 讌
誤 螻殊 蟇一工. Haskell 一危一 伎 磯 襦 るジ 螳 覲語牡襯
螳讌 給.
f :: (Integral a, Num b) => a -> b
f 0 = 0
f 1 = 1
f n = f (n-1) + f (n-2)
Prelude> f 10
55
螳 襷れ広 伎 朱慨豺 襯 蟲ロ 所 讌蟯朱 蟲 給.
3. Pattern matching
襷れ広 覿 谿襦襦 企れる 蟆. 讀, 伎 磯ジ 蟲 螳 襦
るゴ覃 蟆郁骸 殊. 襯 覺.
f :: (Integral a) => a -> String
f n = "must run this function!"
f 0 = "its 0"
f2 :: (Integral a) => a -> String
f2 0 = "its 0"
f2 n = "must run this function!"
伎 磯ジ 語 襷 覦蠖 訖伎襷 蟆郁骸螳 殊.
4. Pattern matching
*Main> f 0
must run this function!
*Main> f 1
must run this function!
*Main> f2 0
its 0
*Main> f2 1
must run this function!
螳 f 蟆曙 f n 螳 襾殊 企伎覃伎, 覈 語 n企朱 伎
焔渚覩襦 f 0 願讌 螳讌 覈詩螻 螳 ろ. 蠏碁 襷れ広 覈(
轟) 伎 螻, 覲企 朱 伎 れ 蟆 燕 蟆 譬給.
5. Pattern matching
襷れ広 ろ 給. 蟆曙 瑚 覦.
foo :: Int -> Int
foo 0 = 0
foo 1 = 1
foo 2 = 2
*Main> f 0
0
*Main> f 4
*** Exception: test.hs:(2,1)-(4,7): Non-exhaustive patterns in
function f
襷れ広 覈 譬襯 伎 襷れ広 蟆 蟆曙 貊伎 .
7. Pattern matching
first :: (a,b,c) -> a
first (x, _, _) = x
second :: (a,b,c) -> b
second (_, y, _) = y
third :: (a,b,c) -> c
third (_, _, z) = z
襷れ広 企 豺 る 螳 覓企 蟯 蟆曙(覘螳 蟯 蟆曙) _
蠍壱碁ゼ 伎.
10. Pattern matching
るジ 覈 螳讌 覯 危エ覺.
length' :: (Num b) => [a] -> b
length' [] = 0
length' (_:xs) = 1 + length' xs
sum' :: (Num a) => [a] -> a
sum' [] = 0
sum' (x:xs) = x + sum' xs
11. Pattern matching
覦 企 一危 豌願 覈 蟆曙 @襯 伎 給.
headFirst :: (Show a) => [a] -> String
headFirst [] = "empty string"
headFirst all@(x:_) = show all ++ "'s first element is " ++ show x
*Main> headFirst [1,2,3,4]
"[1,2,3,4]'s first element is 1"
*Main> headFirst "abcd"
""abcd"'s first element is 'a'"
14. Guard
螳 覲危 螳 譴 螳 螳 譟郁唄螻 蟇郁鍵 企麹 貊襯 危.
譟郁唄 譴 碁危(indent) 譟一 . 螳 危 豺螳 襦
碁危瑚 るゴる 貉危 螳 覦.
覲危 螳 襷 襷讌襷 otherwise. otherwise True襦 朱, るジ
螳螳 豌襴讌 覈詩 譟郁唄 豌襴蠍 譟伎.
願骸 螳襯 螳 蟆曙, 螳 襷譟燕 譟郁唄 蟆曙 れ 伎朱 願.
れ 伎 譟伎讌 る 襷谿螳讌襦 瑚 覦. 蠏碁Μ螻 螳襯 譴 覈
貊襯 蟯讌襷, 螳煙 伎蠍 覓語 覲襦 豢豌襷 覦 蟆 螳れ.
max' :: (Ord a) => a -> a -> a
max' a b | a > b = a | otherwise = b
15. where
where 企 企 覦覲旧朱 一企 煙 . bmiTell
襯 where襯 伎 企慨蟆給.
bmiTell :: (Floating a) => a -> a -> String
bmiTell weight height
| bmi <= 18.5 = "You are underweight."
| bmi <= 25.0 = "You are normal."
| bmi <= 30.0 = "You are fat."
| otherwise = "You are very fat."
where bmi = weight / height ^ 2
れ 覈碁願襯 語襦 覦 bmi讌襯 螻壱伎 蟆 螻, bmi 螻 螻旧
覦覲旧朱 一願鍵 覓語 where 伎給.
16. where
where 貊 螳煙 譴 訖襷 螳 螻一 覯襷 螻壱企 蟆 襷れ伎朱
ろ レ蟾讌 螳語給. where 企 伎 企 伎襷 螳ロ.
where 襷れ広 伎 給.
bmiTell :: (Floating a) => a -> a -> String
bmiTell weight height
| bmi <= skinny = You are underweight.
| bmi <= normal = You are normal.
| bmi <= fat = You are fat.
| otherwise = You are very fat.
where bmi = weight / height ^ 2
(skinny, normal, pat) = (18.5, 25.0, 30.0)
17. where
where 企 襯 誤 朱, where 企 where 譴豌伎
螻, 襯 襷 覓碁( 襷れ広, 螳 ) 覈 螳ロ.
calcFibos :: (Integral a) => [a] -> a
calcFibos xs = [fibo x | x <- xs]
where fibo 0 = 0
fibo 1 = 1
fibo n = fibo (n-1) + fibo (n-2)
18. let in
let in where 螻 觜訣 . let (bindings) in (expression) 襯 螻
朱, where れ binding る 覦覃 let binding る 谿伎 給.
cylinder :: (Num a) => a -> a -> a
cylinder r h =
let sideArea = 2 * pi * r * h
topArea = pi * r^2
in sideArea + 2 * topArea
let in let 覦碁 螳 in れ 給. where 蟲覓語
蟲譟一 覦覃 let in if覓語 貊 企讌 煙ロ 給. 讀, let in
蠏 豌企 螳覃 蟆郁骸 螳 譟伎伎朱 .
19. let in
譴 螳 覦碁 螻 矩る 碁語襦(;) 伎.
Prelude> let a = 5 in a * a * a
125
Prelude> let squre x = x * x in (squre 5, squre 6)
(25, 36)
Prelude> let a = 100; b = 200; c = 300; in a + b + c
600
list comprehension let 給. let 覦碁 襷 .
Prelude> [f x|x<-[0..10],let f 0=0;f 1=1;f n=f (n-1)+f (n-2)]
[0,1,1,2,3,5,8,13,21,34,55]
20. case expression
case 覈麹 語伎 switch - case 蟲覓瑚骸 觜訣 螳企, 螳ロ 蠍磯レ 螳螻
給. case 願鍵 覓語 螳 螳願, 貊 譴螳 給.
蟲覓語 螳 蟲譟磯ゼ 螳螻 給.
case expression of pattern -> result
pattern -> result
pattern -> result
...
語 襷れ広螻 蟲ロ . 轟 伎 磯ジ 蟆郁骸 螳 case
牛 給. る 襷れ広螻朱 るゴ蟆 case 願鍵 覓語
企讌 螳ロ.
21. case expression
head :: [a] -> a
head xs = case xs of [] -> error "Cant call head on empty list."
(x:_) -> x
descList :: [a] -> String
descList xs = "this List is " ++ case xs of [] -> "Empty List"
[x]-> "Singleton List"
xs -> "Long List"