Skip to content

Instantly share code, notes, and snippets.

new oq, qr, n, req. (Init[oq, req] | S[oq, qr] | I[qr, n] | F[n])
S[oq, qr] := oq(req).new query.S_query[qr, query]
S_query[qr, query] := qr<query>.S[qr, qr]
I[qr, n] := qr(query).new response.I_notice[qr, n, response]
I_notice[qr, n, response] := n<response>.I_respond[qr, n, response]
I_respond[qr, n, resp] := qr<resp>.I[qr, n]
F[n] := n(resp).F_recv[n]
F_recv[n] := τ.F[n]
Init[qr, req] := qr<req>
@neko-kai
neko-kai / quantified.scala
Last active April 2, 2019 13:53
Tagless final for ZIO via quantified constraints
package quantified
import cats.Monad
import scala.language.implicitConversions
/**
* C[_] constraint applied to type F[_, _] quantified in first parameter, i.e.
*
* {{{
sealed trait Decidable[+Proof]
final case class Yes[Proof](proof: Proof) extends Decidable[Proof]
final case object No extends Decidable[Nothing]
sealed trait List[+A] {
def nonEmpty: Decidable[this.type <:< ::[A]]
def ::[AA >: A](value: AA): ::[AA] = new ::[AA](value, this)
}
final case object Nil extends List[Nothing] {
def nonEmpty: Decidable[this.type <:< ::[Nothing]] = No
@gvanrossum
gvanrossum / expander.py
Last active October 7, 2023 23:15
Expand variadic type variables
LIMIT = 5
BOUND = 'object'
def prelude(limit: int, bound: str) -> None:
print('from typing import Callable, Iterable, Iterator, Tuple, TypeVar, overload')
print('Ts = TypeVar(\'Ts\', bound={bound})'.format(bound=bound))
print('R = TypeVar(\'R\')')
for i in range(LIMIT):
print('T{i} = TypeVar(\'T{i}\', bound={bound})'.format(i=i+1, bound=bound))

Explaining Miles's Magic

Miles Sabin recently opened a pull request fixing the infamous SI-2712. First off, this is remarkable and, if merged, will make everyone's life enormously easier. This is a bug that a lot of people hit often without even realizing it, and they just assume that either they did something wrong or the compiler is broken in some weird way. It is especially common for users of scalaz or cats.

But that's not what I wanted to write about. What I want to write about is the exact semantics of Miles's fix, because it does impose some very specific assumptions about the way that type constructors work, and understanding those assumptions is the key to getting the most of it his fix.

For starters, here is the sort of thing that SI-2712 affects:

def foo[F[_], A](fa: F[A]): String = fa.toString
@runarorama
runarorama / gist:a8fab38e473fafa0921d
Last active April 13, 2021 22:28
Compositional application architecture with reasonably priced monads
sealed trait Interact[A]
case class Ask(prompt: String)
extends Interact[String]
case class Tell(msg: String)
extends Interact[Unit]
trait Monad[M[_]] {
def pure[A](a: A): M[A]
@tsiege
tsiege / The Technical Interview Cheat Sheet.md
Last active May 5, 2024 04:52
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

ANNOUNCEMENT

I have moved this over to the Tech Interview Cheat Sheet Repo and has been expanded and even has code challenges you can run and practice against!






\

@jbrowning
jbrowning / some_spec.coffee
Last active April 25, 2016 23:38
Angular & CoffeeScript: Error: [ng:areq] Argument 'fn' is not a function, got Object
# The $provide service is used to override an injected dependency
# Bad - results in Error: [ng:areq] Argument 'fn' is not a function, got Object
module 'someModule', ($provide) ->
$provide.value "SomeService", SomeMock
# Good
module 'someModule', ($provide) ->
$provide.value "SomeService", SomeMock
null
import com.lmax.disruptor.dsl.Disruptor
import java.util.concurrent.Executors
import com.lmax.disruptor._
case class ValueEvent(var value: Long)
case class ValueEventTranslator(value: Long) extends EventTranslator[ValueEvent] {
def translateTo(event: ValueEvent, sequence: Long) = {
event.value = value
event
import com.lmax.disruptor.dsl.Disruptor
import java.util.concurrent.Executors
import com.lmax.disruptor._
case class ValueEvent(var value: Long)
case class ValueEventTranslator(value: Long) extends EventTranslator[ValueEvent] {
def translateTo(event: ValueEvent, sequence: Long) = {
event.value = value
event