Discover and read the best of Twitter Threads about #monadicmonday

Most recents (7)

Welcome to twelfth episode of #monadicmonday! Today I want to talk about a Future – a concept of asynchronous lazy task, which is a far better replacement for an eager Promise.
Due to their laziness, futures support cancellation, racing, parallelism and resource safety out of the box. The best library I've seen and used for Futures is fluture-js: github.com/fluture-js/Flu….
Fun fact: in Scala world `Future` is not a monad, but something akin to JS's `Promise` – i.e., eager referentially non-transparent construct. Instead, it's far better to use IO (cats), Task (monix & scalaz) or ZIO (zio) to achieve the described benefits of today's topic.
Read 13 tweets
Welcome to ninth episode of #monadicmonday! Today I would like to return to the roots of this series and provide you with a few "take and go" recepies for type-level programming in TypeScript.
Let's start with the basics. Type-level programming means that we express statements using types, and ask compiler to check them. In TypeScript, we use conditional types to infer our statements to be either `never` (bottom type) or some meaningful type.
The first useful operation is type-level `If` operator, which can be expressed like so:
Read 25 tweets
Welcome to the seventh episode of #monadicmonday! Today we'll talk a bit about functional optics: lenses, prisms, folds and traversals.
History of lenses started in 2009 with "The Essence of the Iterator Pattern" paper, which started a whole lot of cascading publications, leading to current `lens` package for Haskell and various implementations in different languages.
I will use an awesome `monocle-ts` package from @GiulioCanti for this episode, but you may use any optics library you find suitable. The concepts are the same.

You can find more historical references at github.com/ekmett/lens/wi…
Read 24 tweets
Welcome to the fifth episode of #monadicmonday! Today we'll look at the famous Tagless Final pattern and its implementation in TypeScript.

If you haven't heard of Tagless Final style (also called "Finally Tagless Interpreters"), here's a brief recap.
Originally this pattern was introduced by Oleg Kiselyov et al. in his paper "Finally Tagless, Partially Evaluated: Tagless Staged Interpreters for Simpler Typed Languages": okmij.org/ftp/tagless-fi…
TF style is a general method of embedding domain-specific languages (DSL) in a typed functional language. It effectively separates eDSL statements from their interpreters, allowing building a robust extensible applications.
Read 18 tweets
Welcome to the thrid installment of #monadicmonday!
Today we'll talk about quite complicated topic – recursion schemes. Hold tight, as the ride won't be easy.

First of all, I would like to stress that I'm still grokking this topic, so if you spot a mistake, please ping me back!
Recursion schemes were popularized by a classical paper by Mejer, Fokkinga and Petterson called "Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire": eprints.eemcs.utwente.nl/7281/01/db-utw…
Recursion schemes are powerful way to generalize various recursion algorithms and make them composable and easy to reason about. Importance of recursion schemes for FP is of the same scale as importance of design patterns for OOP.
Read 22 tweets
Welcome to the second episode of #monadicmonday! Today we'll talk about algebraic data types, and more specifically – about semirings and rings.
First of all, let's recap what a semiring is.
Semiring is a set equipped with two binary operations, called "addition" and "multiplication". The intuition that works here is such of natural numbers – you can define a semiring for Nat with addition as "+" and multiplication as "*"
A ring extends a semiring with an additional "inverse" operation (or, strictly speaking, ring implies that for each 'a' there exists '-a').
Rings and semirings must also have "zero" and "one" elements, and multiplication should distribute over addition.
Read 11 tweets
Welcome to #monadicmonday! Let's start with a These/Ior monad.

`These` is a monad which expresses "inclusive-OR" relation:

These(A, B) = A + B + A * B.

These represents a simple idea: it can hold either value of type A, value of type B or both of them simultaneously.
It may be present in FP libraries under it's literal name "These" (Haskell, TypeScript), or under "Ior" name (like in Scala's `cats` package).

Take a look at the following function in TypeScript using These monad from fp-ts package by @GiulioCanti:
@GiulioCanti Now let's look at the examples. Note that we need to provide all possible "handlers" to `fold` function,
so the monad could be reduced to a single value.
Read 5 tweets

Related hashtags

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!