Skip to content

Instantly share code, notes, and snippets.

@nomisRev
nomisRev / transactionEither.kt
Last active August 10, 2022 08:41
Either-Syntax for SqlDelight transactions
import arrow.continuations.Effect
import arrow.continuations.generic.DelimitedScope
import arrow.core.Either
import arrow.core.right
import com.squareup.sqldelight.TransactionWithReturn
import kotlin.coroutines.RestrictsSuspension
/**
* Either-Syntax for SqlDelight transactions.
*
@graninas
graninas / haskell_design_patterns.md
Last active May 11, 2024 12:56
Haskell Design Patterns

Design patterns in Haskell

This is a list of patterns. I'm collecting this list with an idea to write a book similar to the GoF book.

My patterns:

  • Typed / Untyped pattern
  • Typed Avatar pattern (see Hydra and Node)
    • Typed Options pattern (see EulerHS)
  • Control Structure pattern (see CLI control structure in Hydra and similar in Node)

Some thoughts on building software

Lately I have been busy reading some new books on Domain Driven Design (DDD) and software architecture -- including a short yet eye-opening one in Python and a great one in F#. At the same time, it seems that more people in the Functional Programming world are looking at more formal approaches to modelling -- some examples here. This has brought some thought from the background of my brain about how we should model, organize, and architect software using the lessons we've learnt from functional programming.

Before moving on, let me be clear about this being just a dump of some thoughts, not always well-defined, definite

@lazamar
lazamar / LongestSubsequences.hs
Created March 1, 2020 02:49
Longest Increasing Subsequence and Longest Common Subsequence
import Data.Function
import Data.List
import Data.Maybe
import qualified Data.Set as Set
import qualified Data.Map as Map
-- Longest increasing subsequence
-- O(nlogn)
lis :: Ord a => [a] -> [a]
lis = buildResult . snd . mapAccumL takeMax (Set.empty, Nothing)
@atacratic
atacratic / pipe.u
Created January 29, 2020 00:39
example multihandler in Unison
-- An example multihandler.
-- Pipe messages out of the first argument computation into the second.
pipe : Request (Send m) () -> Request (Receive m) a ->{Abort} a
pipe sender receiver =
case receiver of
{ Receive.receive -> kr } ->
case sender of
{ Send.send m -> ks } -> pipe (step ks) (step '(kr m))
{ _ } -> Abort.abort
{ a } -> a
@atacratic
atacratic / ability-tutorial.output.md
Last active October 22, 2024 20:55
Unison abilities - unofficial alternative tutorial

This tutorial explains how Unison handles 'effectful' computations, like storing state or performing I/O, using abilities. It assumes you haven't come across abilities before, and covers everything from the ground up.

This is an unofficial tutorial, written before the one on unisonweb.org/docs. The approach taken here is slow and methodical. Your first stop should be the official tutorial, if you haven't seen it already.

This doc is a Unison transcript - the source is here.

Terminology note: other languages with ability systems typically call them 'effect handlers' or 'algebraic effects', but many of the ideas are the same.

Introducing abilities

@rampion
rampion / LetsGetDangerous.md
Last active January 20, 2020 05:02
Let's Get Dangerous
@PhBastiani
PhBastiani / # ArrowFreePrograms.md
Last active May 27, 2022 15:56
[arrow-kt] Free programs in Kotlin. Additional notes.

Free programs in Kotlin - GADT & ADT Alternatives

Copyright © 2020, Philippe Bastiani.
License: CC BY-NC-SA 4.0

These are additional notes to this GIST : For-Comprehension Free Monads in Kotlin - Mini Howto.

Disclaimer: This GIST assumes that you are roughly familiar with the concept of Free monad.

Source-code compatibility

Λrrow 0.10 (now deprecated)

@runarorama
runarorama / day1.markdown
Last active December 8, 2019 12:42
Advent of Code (Unison Edition), day 1

Advent of Code 2019, in Unison

Spoilers for Advent of Code 2019 follow.

Day 1: The Tyranny of the Rocket Equation

Fuel required to launch a given module is based on its mass. Specifically, to find the fuel required for a module, take its mass, divide by three, round down, and subtract 2.

This describes a simple function. There seems to be an oversight in the problem statement that modules with very low mass have a negative fuel requirement. I'm going to assume that's not right, and that instead of integer subtraction, we want natural number subtraction (sometimes called "monus"). In Unison, we can use the Nat type instead of integers, so we don't have to consider negatives. The subtraction operation is called drop: