Or, Strings with "" as the empty element and + (string concatenation). Or, Ints with 1 as the empty element and * as the operation. For example, Ints with 0 as the empty element and + as the operation are the simplest example. combine(x, empty) = combine(empty, x) = x: empty is the neutral element of combine.combine(x, combine(y, z)) = combine(combine(x, y), z): combine is associative.There are two restrictions on how these operations should behave: We'll be also using some other constructs common in Functional Programming, and if possible at all in a brief way, I'll try to introduce them so hopefully the article will be understandable for FP-beginners as well (if not, please ask questions in the comments!).įinally, if you'd like a "use it now" version, skip to the last section :) MonoidsĪ monoid is a data type (such as Int, String, or your own Foo), let's call it A, together with two operations (methods): Feel free to skip to the next section if you are already familiar with the concept. We'll be using a lot of monoids, so the next section will briefly introduce them. Being only a theoretical Haskell coder, and a much more practical Scala one, I started to wonder if the folds would be equally beautiful in Scala. As this is a Haskell conference, the talk (unsurprisingly) used Haskell as the base language. I've recently watched a talk by Gabriel Gonzalez on "Beautiful Folds" ( slides, video), given at MuniHac 2016.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |