Learning Scalaz

Learning Scalaz

learning Scalaz eugene yokota (@eed3si9n) Contents preface .................................... 10 Links .................................. 10 day 0 ..................................... 10 Intro to Scalaz ............................ 10 What is polymorphism? .......................... 11 Parametric polymorphism ...................... 11 Subtype polymorphism ........................ 12 Ad-hoc polymorphism ........................ 12 sum function ............................. 13 Monoid ................................ 13 FoldLeft ................................ 16 Typeclasses in Scalaz ......................... 17 Method injection (enrich my library) ................ 17 Standard type syntax ........................ 18 day 1 ..................................... 19 typeclasses 101 ............................ 19 sbt ................................... 19 Equal ................................. 20 Order ................................. 21 Show .................................. 22 Read .................................. 22 Enum ................................. 22 1 Bounded ................................ 23 Num .................................. 24 typeclasses 102 ............................ 24 A traffic light data type ....................... 24 a Yes-No typeclass .......................... 25 day 2 ..................................... 28 Functor ................................ 28 Function as Functors ......................... 29 Applicative .............................. 31 Apply ................................. 33 Option as Apply ........................... 34 Applicative Style ........................... 34 Lists as Apply ............................. 34 Zip Lists ................................ 35 Useful functions for Applicatives .................. 35 day 3 ..................................... 37 Kinds and some type-foo ....................... 37 Tagged type .............................. 40 About those Monoids ........................ 41 Monoid ................................ 42 Semigroup ............................... 43 Back to Monoid ............................ 44 Tags.Multiplication .......................... 44 Tags.Disjunction and Tags.Conjunction .............. 45 Ordering as Monoid ......................... 45 day 4 ..................................... 47 Functor Laws ............................. 47 Breaking the law ........................... 49 Applicative Laws ........................... 50 Semigroup Laws ........................... 51 Monoid Laws ............................. 51 2 Option as Monoid .......................... 52 Foldable ................................ 53 day 5 ..................................... 55 A fist full of Monads ......................... 56 Bind .................................. 56 Monad ................................. 57 Walk the line ............................. 57 Banana on wire ............................ 59 for syntax ............................... 61 Pierre returns ............................. 62 Pattern matching and failure .................... 63 List Monad .............................. 64 MonadPlus and the guard function ................. 64 Plus, PlusEmpty, and ApplicativePlus ............... 65 MonadPlus again ........................... 66 A knight’s quest ........................... 66 Monad laws .............................. 67 day 6 ..................................... 69 for syntax again ............................ 69 Writer? I hardly knew her! ..................... 70 Writer ................................. 71 WriterT ................................ 71 Using for syntax with Writer .................... 72 Adding logging to program ..................... 73 Inefficient List construction ..................... 73 Comparing performance ....................... 74 Reader ................................. 75 day 7 ..................................... 77 Applicative Builder .......................... 77 Tasteful stateful computations ................... 77 State and StateT ........................... 78 3 Getting and setting state ...................... 79 / .................................... 81 Validation ............................... 84 NonEmptyList ............................ 85 day 8 ..................................... 86 Some useful monadic functions ................... 86 Making a safe RPN calculator .................... 88 Composing monadic functions .................... 89 Kleisli ................................. 90 Reader again ............................. 91 Making monads ............................ 91 day 9 ..................................... 94 Tree .................................. 94 TreeLoc ................................ 96 Zipper ................................. 99 Id ................................... 101 Lawless typeclasses ............................. 102 Length ................................. 102 Index ................................. 103 Each .................................. 103 Foldable or rolling your own? .................... 104 Pointed and Copointed ........................ 104 Tweets to the editor ......................... 104 day 10 .................................... 104 Monad transformers ......................... 105 Reader, yet again ........................... 105 ReaderT ................................ 105 Stacking multiple monad transformers ............... 107 day 11 .................................... 109 Lens .................................. 109 LensT ................................. 111 4 Store .................................. 111 Using Lens .............................. 112 Lens as a State monad ........................ 113 Lens laws ............................... 115 Links .................................. 115 day 12 .................................... 116 Origami programming ........................ 116 DList ................................. 116 Folds for Streams ........................... 117 The Essence of the Iterator Pattern ................. 118 Monoidal applicatives ........................ 118 Combining applicative functors ................... 118 Idiomatic traversal .......................... 120 Shape and contents .......................... 121 Sequence ................................ 123 Collection and dispersal ....................... 124 Links .................................. 125 day 13 (import guide) ........................... 125 implicits review ............................ 126 import scalaz._ ............................ 126 import Scalaz._ ............................ 127 a la carte style ............................ 132 day 14 .................................... 134 mailing list .............................. 134 git clone ................................ 134 sbt ................................... 135 including Vector ........................... 135 snapshot ................................ 137 <*> operator ............................. 137 applicative functions ......................... 139 day 15 .................................... 142 5 Arrow ................................. 143 Category and Compose ....................... 143 Arrow, again ............................. 144 Unapply ................................ 145 parallel composition ......................... 147 day 16 .................................... 152 Memo ................................. 152 functional programming ....................... 154 Effect system ............................. 154 ST ................................... 154 STRef ................................. 155 Interruption .............................. 157 Back to the usual programming ................... 159 day 17 .................................... 160 IO Monad ............................... 161 Enumeration-Based I/O with Iteratees ............... 163 Composing Iteratees ......................... 166 File Input With Iteratees ...................... 166 Links .................................. 168 day 18 .................................... 168 Func .................................. 168 Free Monad ................................. 169 CharToy ................................ 169 Fix ................................... 170 FixE .................................. 171 Free monads part 1 .......................... 172 Free monads part 2 .......................... 177 Free monads part 3 .......................... 177 Stackless Scala with Free Monads ..................... 177 Free monads .............................. 178 Trampoline .............................. 179 6 List using Free ............................ 180 day 19 .................................... 180 Category theory ........................... 181 Sets, arrows, composition ...................... 181 Point .................................. 185 Equality of arrows of sets ...................... 186 Isomorphisms ............................. 188 Determination and choice ...................... 190 Retractions and sections ....................... 191 Surjective ............................... 191 Injective and monomorphism .................... 193 Epimorphism ............................. 194 Idempotent .............................. 194 Automorphism ............................ 194 day 20 .................................... 194 Awodey’s ‘Category Theory’ ..................... 194 Examples of categories ........................... 195 Sets .................................. 195 Setsfin ................................. 195 Pos ................................... 195 Cat ................................... 196 Monoid ................................ 196

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    224 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us