# Monad

Published articles for Monad.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Implementing Unsure Calculator in 100 lines of Haskell

DevFeed: [Implementing Unsure Calculator in 100 lines of Haskell](<https://devfeed.tech/articles/implementing-unsure-calculator-in-100-lines-of-haskell-27917.md>)

Original publisher: [Read original article](<http://alt-romes.github.io/posts/2025-04-25-unsure-calculator-in-100-lines-of-haskell.html>)

Published: 2025-04-25T00:00:00Z

Content type: tutorial

Language: en

Sources: [Romes' Musings](<https://devfeed.tech/sources/romes-musings.md>)

Topics: [Haskell](<https://devfeed.tech/topics/haskell.md>), [Development](<https://devfeed.tech/topics/development.md>), [math](<https://devfeed.tech/topics/math.md>)

Tags: [article](<https://devfeed.tech/tags/article.md>), [expression](<https://devfeed.tech/tags/expression.md>), [haskell](<https://devfeed.tech/tags/haskell.md>), [list](<https://devfeed.tech/tags/list.md>), [monad](<https://devfeed.tech/tags/monad.md>), [numbers](<https://devfeed.tech/tags/numbers.md>), [operations](<https://devfeed.tech/tags/operations.md>), [range](<https://devfeed.tech/tags/range.md>)

### AI overview

This tutorial implements an Unsure Calculator in Haskell. It introduces a range operator for uncertain values, models calculations with a probability monad and normal distributions, samples results using pseudo-randomness, and builds an embedded calculator expression language.

### Source excerpt

Contents 1 Unsure Calculator 1.1 Sampling it up 1.2 Calculator Expressions 1.3 Showing up 1.4 Conclusion 1 Unsure Calculator The recently trendy Unsure Calculator makes reasoning about numbers with some uncertainty just as easy as calculating with specific numbers. The key idea is to add a new "range" operator (written ~) to the vocabulary of a standard calculator. The range x~y denotes that a real value is uncertain, but we are 95% sure that it falls between x and y1. Reading the notation is easy: when you see 10~15, you say: "ten to fifteen". Arithmetic operations and friends (e.g. sin, or log) transparently operate on ranges and literal numbers alike. Calculation results in a plot with a range of values that the input expression can take, and with what frequency. The motivation behind the original article is neat, so I'll just recommend you read it there to learn how and why you'd use such a calculator. Here's a real life example they used: 1400~1700 * 0.55~0.65 - 600~700 - 100~200 - 30 - 20 Now, let's implement it. 1.1 Sampling it up Summon a probability monad from the void2. data Dist a where Return :: a -> Dist a Bind :: Dist b -> (b -> Dist a) -> Dist a Normal :: Double -> Double -> Dist Double instance Monad Dist where (>>=) = Bind instance Applicative Dist where pure = Return; (<*>) = ap instance Functor Dist where fmap = liftM The monad instance is free: pure = Return and (>>=) = Bind. The Normal constructor denotes a normal distribution given the standard deviation and mean. With do-notation we can easily construct a complex tree mixing Returns, Binds, and Normals. For instance: d = do s <- Normal 0 1 return (5 + s) desugars to d = Bind (Normal 0 1) (\s -> Return (5 + s)) Then, embue meaning onto a Dist a by allowing an a to be sampled according to the distribution the Dist represents. We use StdGen from random as a source of uniform pseudo-randomness: sample :: StdGen -> Dist a -> a sample g d = case d of Return x -> x Normal mean std_dev -> n1 * std_dev

## KotlinConf'23-Kotlin & Functional Programming: pick the best, skip the rest by Urs Peter

DevFeed: [KotlinConf'23-Kotlin & Functional Programming: pick the best, skip the rest by Urs Peter](<https://devfeed.tech/articles/kotlinconf-23-kotlin-functional-programming-pick-the-best-skip-the-rest-by-urs-peter-27026.md>)

Original publisher: [Read original article](<https://appmattus.medium.com/kotlinconf23-kotlin-functional-programming-pick-the-best-skip-the-rest-by-urs-peter-8958d3dcb432?source=rss-be40b368c57e------2>)

Author: Matthew Dolan

Published: 2023-04-14T06:32:47Z

Content type: opinion

Language: en

Sources: [Stories by Matthew Dolan on Medium](<https://devfeed.tech/sources/stories-by-matthew-dolan-on-medium.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Functional programming](<https://devfeed.tech/topics/functional-programming.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [exceptions](<https://devfeed.tech/topics/exceptions.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [arrow](<https://devfeed.tech/tags/arrow.md>), [data-structures](<https://devfeed.tech/tags/data-structures.md>), [exceptions](<https://devfeed.tech/tags/exceptions.md>), [functional-programming](<https://devfeed.tech/tags/functional-programming.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [monad](<https://devfeed.tech/tags/monad.md>), [optional](<https://devfeed.tech/tags/optional.md>), [programming](<https://devfeed.tech/tags/programming.md>)

### AI overview

A review of Urs Peter's KotlinConf'23 talk on functional programming, covering monoids, functors, monads, and selective use of the Arrow framework. It highlights using Either for recoverable service errors, nullable comprehensions, and Arrow Optics for nested data updates.

### Source excerpt

KotlinConf'23 -- Kotlin & Functional Programming: pick the best, skip the rest by Urs Peterhttps://medium.com/media/b5b95f6bdbb507930534ef8279ba1d05/href I recently had the pleasure of listening to Urs Peter's talk on Kotlin & Functional. The speaker gave a great, simple summary of what a Monad is and how it works. In essence: a Monoid is combinable (plus) and has an identity (empty) element which when combined with another value returns that other value. a Functor is mappable (map) a Monad is composable (flatMap) The talk then went on to discuss some common monads, such as Collections and Optional. The highlight of the talk for me was when the speaker talked about cherry-picking the best features between Kotlin and Monads (using the Arrow framework). Use Monads selectively where needed and useful. Why use a Monad to replace try-catch blocks for the 95% of use cases? Let exceptions bubble up to a GlobalExceptionHandler. For the other 5%, where we're typically recovering in our service, prefer Either<A,B> over Result as it makes the contract explicit with easy access to the error reply. Prevent tedious null checks with Arrow's nullable{ } comprehension. With deeply nested data structures where you want to change something at the leaf level, use Arrow Optics instead of nested copy calls. While I enjoyed the talk, I would have loved to hear more best features. You can find my thoughts on more KotlinConf'23 talks at KotlinConf'23. Please let me know your thoughts. Join medium to read all of my articles or subscribe for e-mail updates.

## Continuation\<R, A\> in Kotlin

DevFeed: [Continuation\<R, A\> in Kotlin](<https://devfeed.tech/articles/continuation-r-a-in-kotlin-25512.md>)

Original publisher: [Read original article](<http://nomisrev.github.io/continuation-monad-in-kotlin/>)

Author: Simon Vergauwen

Published: 2021-11-28T00:00:00Z

Content type: tutorial

Language: en

Sources: [nomisRev](<https://devfeed.tech/sources/nomisrev.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Coroutines](<https://devfeed.tech/topics/coroutines.md>), [Functional programming](<https://devfeed.tech/topics/functional-programming.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [continuation](<https://devfeed.tech/tags/continuation.md>), [coroutines](<https://devfeed.tech/tags/coroutines.md>), [effect](<https://devfeed.tech/tags/effect.md>), [either](<https://devfeed.tech/tags/either.md>), [exception](<https://devfeed.tech/tags/exception.md>), [functional-programming](<https://devfeed.tech/tags/functional-programming.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-standard-library](<https://devfeed.tech/tags/kotlin-standard-library.md>), [monad](<https://devfeed.tech/tags/monad.md>), [suspend-function](<https://devfeed.tech/tags/suspend-function.md>), [syntax](<https://devfeed.tech/tags/syntax.md>)

### AI overview

A Kotlin tutorial introduces Continuation Passing Style and typed computations that can represent either a successful result or a typed failure. It develops an Effect type implemented as a suspend function and demonstrates a DSL for validation and file-reading examples.

### Source excerpt

Coroutines is one of the most liked features in Kotlin. Most people are familiar with the KotlinX Coroutines implementation, and many are also familiar with suspendCoroutine from the Kotlin Standard Library and then have also come across Continuation.

## Latent Effects for Reusable Language Components

DevFeed: [Latent Effects for Reusable Language Components](<https://devfeed.tech/articles/latent-effects-for-reusable-language-components-29486.md>)

Original publisher: [Read original article](<http://lambda-the-ultimate.org/node/5640>)

Published: 2021-10-14T14:02:48Z

Content type: article

Language: en

Sources: [Lambda the Ultimate](<https://devfeed.tech/sources/lambda-the-ultimate.md>)

Topics: [Haskell](<https://devfeed.tech/topics/haskell.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Development](<https://devfeed.tech/topics/development.md>), [implementation](<https://devfeed.tech/topics/implementation.md>)

Tags: [abstraction](<https://devfeed.tech/tags/abstraction.md>), [deferred](<https://devfeed.tech/tags/deferred.md>), [effects](<https://devfeed.tech/tags/effects.md>), [examples](<https://devfeed.tech/tags/examples.md>), [functional](<https://devfeed.tech/tags/functional.md>), [haskell](<https://devfeed.tech/tags/haskell.md>), [modular](<https://devfeed.tech/tags/modular.md>), [monad](<https://devfeed.tech/tags/monad.md>), [programming-languages](<https://devfeed.tech/tags/programming-languages.md>), [semantics](<https://devfeed.tech/tags/semantics.md>), [theory](<https://devfeed.tech/tags/theory.md>)

### AI overview

The article discusses latent effects, a generic class of control-flow mechanisms for modular language definitions. It describes how function abstractions, lazy computations, and MetaML-like staging can be expressed and combined, with a full Haskell implementation and examples.

### Source excerpt

Latent Effects for Reusable Language Components, by Birthe van den Berg, Tom Schrijvers, Casper Bach Poulsen, Nicolas Wu: The development of programming languages can be quite complicated and costly. Hence, much effort has been devoted to the modular definition of language features that can be reused in various combinations to define new languages and experiment with their semantics. A notable outcome of these efforts is the algebra-based "datatypes "a la carte" (DTC) approach. When combined with algebraic effects, DTC can model a wide range of common language features. Unfortunately, the current state of the art does not cover modular definitions of advanced control-flow mechanisms that defer execution to an appropriate point, such as call-by-name and call-by-need evaluation, as well as (multi-)staging. This paper defines latent effects, a generic class of such control-flow mechanisms. We demonstrate how function abstractions, lazy computations and a MetaML-like staging can all be expressed in a modular fashion using latent effects, and how they can be combined in various ways to obtain complex semantics. We provide a full Haskell implementation of our effects and handlers with a range of examples. Looks like a nice generalization of the basic approach taken by algebraic effects to more subtle contexts. Algebraic effects have been discussed here on LtU many times. I think this description from section 2.3 is a pretty good overview of their approach: LE&H is based on a different, more sophisticated structure than AE&H's free monad. This structure supports non-atomic operations (e.g., function abstraction, thunking, quoting) that contain or delimit computations whose execution may be deferred. Also, the layered handling is different. The idea is still the same, to replace bit by bit the structure of the tree by its meaning. Yet, while AE&H grows the meaning around the shrinking tree, LE&H grows little "pockets of meaning" around the individual nodes remaining in the

## The Result Monad

DevFeed: [The Result Monad](<https://devfeed.tech/articles/the-result-monad-25659.md>)

Original publisher: [Read original article](<https://adambennett.dev/2020/05/the-result-monad/>)

Published: 2020-05-15T17:31:46Z

Content type: tutorial

Language: en

Sources: [Posts on Adam Bennett](<https://devfeed.tech/sources/posts-on-adam-bennett.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Library](<https://devfeed.tech/topics/library.md>), [Error Handling](<https://devfeed.tech/topics/error-handling.md>), [Exception](<https://devfeed.tech/topics/exception.md>), [Android](<https://devfeed.tech/topics/android.md>), [Programming](<https://devfeed.tech/topics/programming.md>)

Tags: [algorithms](<https://devfeed.tech/tags/algorithms.md>), [android](<https://devfeed.tech/tags/android.md>), [blog](<https://devfeed.tech/tags/blog.md>), [career](<https://devfeed.tech/tags/career.md>), [compose](<https://devfeed.tech/tags/compose.md>), [development](<https://devfeed.tech/tags/development.md>), [engineering](<https://devfeed.tech/tags/engineering.md>), [error-handling](<https://devfeed.tech/tags/error-handling.md>), [exception](<https://devfeed.tech/tags/exception.md>), [finance](<https://devfeed.tech/tags/finance.md>), [functional](<https://devfeed.tech/tags/functional.md>), [growth](<https://devfeed.tech/tags/growth.md>), [java](<https://devfeed.tech/tags/java.md>), [jetpack](<https://devfeed.tech/tags/jetpack.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [library](<https://devfeed.tech/tags/library.md>), [monad](<https://devfeed.tech/tags/monad.md>), [money](<https://devfeed.tech/tags/money.md>), [opinions](<https://devfeed.tech/tags/opinions.md>), [programming](<https://devfeed.tech/tags/programming.md>), [software](<https://devfeed.tech/tags/software.md>), [startups](<https://devfeed.tech/tags/startups.md>), [the-result](<https://devfeed.tech/tags/the-result.md>), [thoughts](<https://devfeed.tech/tags/thoughts.md>), [training](<https://devfeed.tech/tags/training.md>), [tutorial](<https://devfeed.tech/tags/tutorial.md>)

### AI overview

This tutorial explains why the Cuvva Android team adopted the kotlin-result library, how Result-based error handling works, and what problems it addresses. It introduces the monad concept and discusses Kotlin's unchecked exceptions in comparison with Java's checked exceptions.

### Source excerpt

Recently I've come to really appreciate the kotlin-result library as we've integrated it more and more deeply into the Cuvva Android stack. In this post, I'll explain why we needed it, how it works and what problems it solves, and show some examples of how we use it at the end. A great many people have tried and failed to explain what a monad is, and this is my attempt at being added to the list.

## Failjure: Exception-free error handling for Clojure

DevFeed: [Failjure: Exception-free error handling for Clojure](<https://devfeed.tech/articles/failjure-exception-free-error-handling-for-clojure-32137.md>)

Original publisher: [Read original article](<https://adambard.com/blog/introducing-failjure/>)

Published: 2016-01-30T00:00:00Z

Content type: release

Language: en

Sources: [Adam Bard](<https://devfeed.tech/sources/adam-bard.md>)

Topics: [Clojure](<https://devfeed.tech/topics/clojure.md>), [Error Handling](<https://devfeed.tech/topics/error-handling.md>), [Library](<https://devfeed.tech/topics/library.md>), [exceptions](<https://devfeed.tech/topics/exceptions.md>)

Tags: [clojure](<https://devfeed.tech/tags/clojure.md>), [error-handling](<https://devfeed.tech/tags/error-handling.md>), [exceptions](<https://devfeed.tech/tags/exceptions.md>), [library](<https://devfeed.tech/tags/library.md>), [monad](<https://devfeed.tech/tags/monad.md>)

### AI overview

The article introduces Failjure, a Clojure utility library for exception-free error handling. It describes returning failure values instead of throwing exceptions, short-circuiting with built-in helpers, wrapping exceptions as failures, and distinguishing expected faults from unexpected errors.

### Source excerpt

I've written before about handling errors in Clojure without using exceptions, by making use of ad-hoc monads. In that post, I also referenced Andrew Brehaut's error monad implementation. Since then, I've written a number of projects that use similar handling, and I thought the time had come to wrap it up in a library, which I'm calling Failjure.

## Error Handling in Clojure with Value-and-Error Results

DevFeed: [Error Handling in Clojure with Value-and-Error Results](<https://devfeed.tech/articles/good-enough-error-handling-in-clojure-32093.md>)

Original publisher: [Read original article](<https://adambard.com/blog/acceptable-error-handling-in-clojure/>)

Published: 2013-05-13T00:00:00Z

Content type: tutorial

Language: en

Sources: [Adam Bard](<https://devfeed.tech/sources/adam-bard.md>)

Topics: [Clojure](<https://devfeed.tech/topics/clojure.md>), [Error Handling](<https://devfeed.tech/topics/error-handling.md>), [exceptions](<https://devfeed.tech/topics/exceptions.md>), [function](<https://devfeed.tech/topics/function.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [clojure](<https://devfeed.tech/tags/clojure.md>), [code](<https://devfeed.tech/tags/code.md>), [error-handling](<https://devfeed.tech/tags/error-handling.md>), [exceptions](<https://devfeed.tech/tags/exceptions.md>), [function](<https://devfeed.tech/tags/function.md>), [monad](<https://devfeed.tech/tags/monad.md>)

### AI overview

This tutorial presents a pragmatic approach to error handling in Clojure by returning either a value or an error message instead of throwing exceptions. It progressively composes validators and ends with a simple error-monad-like pattern.

### Source excerpt

Writing Clojure is not like writing Java. In Java, exceptions are an accepted part of the workflow; in Clojure, they are begrudgingly supported out of necessity, but generally avoided. Why is that? Probably because writing code that throws exceptions makes your functional code a lot less functional - that is, a lot less composable. When you can't trust a function to execute and return a value you lose some functional purity.