Skip to content

Instantly share code, notes, and snippets.

View AesaKamar's full-sized avatar
👾

Aesa Kamar AesaKamar

👾
View GitHub Profile
@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

@agolovenko
agolovenko / InformationSize.scala
Created June 15, 2021 17:15
InformationSize: scala implementation for human-readable file sizes
final case class InformationSize(size: Double, unit: InformationUnit) extends Ordered[InformationSize] {
import InformationSize.{safeAdd, safeDivide, safeMultiply}
import InformationUnit._
if (size < 0d) throw new IllegalArgumentException(s"Unsupported negative size: $size")
def toBits: Double = to(Bit)
def toKiloBits: Double = to(KiloBit)
def toMegaBits: Double = to(MegaBit)
def toBytes: Double = to(Byte)