Skip to content

Instantly share code, notes, and snippets.

View debasishg's full-sized avatar
🏠
Working from home

Debasish Ghosh debasishg

🏠
Working from home
View GitHub Profile
@non
non / laws.md
Last active February 20, 2022 00:26
I feel like conversations around laws and lawfulness in Scala are often not productive, due to a lack of rigor involved. I wanted to try to be as clear and specific as possible about my views of lawful (and unlawful) behavior, and what I consider a correct and rigorous way to think about laws (and their limits) in Scala.

Laws

A law is a group of two or more expressions which are required to be the same. The expressions will usually involve one or more typed holes ("inputs") which vary.

Some examples:

x.map(id) === x
@etorreborre
etorreborre / lawvere.txt
Last active June 23, 2016 03:22
Lawvere theories and effects
The Category Theoretic Understanding of Universal Algebra: Lawvere Theories andMonads:
- http://www.pps.univ-paris-diderot.fr/~mellies/mpri/mpri-ens/articles/hyland-power-lawvere-theories-and-monads.pdf
- interesting for the historical part on how both concepts were developed
Just do it: simple monadic equational reasoning
- http://www.cs.ox.ac.uk/jeremy.gibbons/publications/mr.pdf
- laws for effects
Lawvere theories made a bit easier
- http://blog.sigfpe.com/2012/02/lawvere-theories-made-bit-easier.html
@guersam
guersam / Hittable.scala
Last active October 19, 2015 17:56
Generic update without `.copy`
sealed trait Character
case class Player(hp: Int) extends Character
case class Civilian(name: String, hp: Int) extends Character
case class Monster(hp: Int, weakness: String) extends Character
object HittableDemo extends App {
import Hittable.ops._
val c1: Character = Player(1)
assert(c1.hit == Player(0))

Actor Queue Notes

The first thing to understand is that the head field inside of scalaz.concurrent.Actor is not the "head" of the message queue in any traditional sense of the word. A better description would be "last". The there are no pointers to the head of the queue, which one of the very clever things about this implementation.

Empty Actor

Consider the case where the actor has no outstanding messages. This new message will go into the following code:

 def !(a: A): Unit = {
@djspiewak
djspiewak / streams-tutorial.md
Created March 22, 2015 19:55
Introduction to scalaz-stream

Introduction to scalaz-stream

Every application ever written can be viewed as some sort of transformation on data. Data can come from different sources, such as a network or a file or user input or the Large Hadron Collider. It can come from many sources all at once to be merged and aggregated in interesting ways, and it can be produced into many different output sinks, such as a network or files or graphical user interfaces. You might produce your output all at once, as a big data dump at the end of the world (right before your program shuts down), or you might produce it more incrementally. Every application fits into this model.

The scalaz-stream project is an attempt to make it easy to construct, test and scale programs that fit within this model (which is to say, everything). It does this by providing an abstraction around a "stream" of data, which is really just this notion of some number of data being sequentially pulled out of some unspecified data source. On top of this abstraction, sca

@johnynek
johnynek / AliceInAggregatorLand.scala
Last active January 24, 2024 19:38
A REPL Example of using Aggregators in scala
/**
* To get started:
* git clone https://github.com/twitter/algebird
* cd algebird
* ./sbt algebird-core/console
*/
/**
* Let's get some data. Here is Alice in Wonderland, line by line
*/
@johnmyleswhite
johnmyleswhite / gist:14dbd928019669faef82
Last active August 29, 2015 14:06
Benchmarking Resources
@pchiusano
pchiusano / buffer.scala
Created August 6, 2014 01:21
Buffer type with purely functional API, using a mutable buffer and cheap copy-on-write scheme
import java.util.concurrent.atomic._
import collection.mutable.ArrayBuffer
/**
* Buffer type with purely functional API, using mutable
* `ArrayBuffer` and cheap copy-on-write scheme.
* Idea described by Bryan O'Sullivan in http://www.serpentine.com/blog/2014/05/31/attoparsec/
*/
class Buffer[A](id: AtomicLong, stamp: Long, values: ArrayBuffer[A], size: Int) {
@pchiusano
pchiusano / finallytagless.scala
Last active March 13, 2018 11:28
Finally tagless encoding of GADTs in Scala
trait ConsoleAlg[F[_]] {
def readLine: F[Option[String]]
def printLine(line: String): F[Unit]
}
trait Console[+A] {
def run[F[+_]](F: ConsoleAlg[F]): F[A]
}
object Console {