Skip to content

Instantly share code, notes, and snippets.

View acrylic-origami's full-sized avatar

Derek Lam acrylic-origami

View GitHub Profile
@acrylic-origami
acrylic-origami / AsteriusPrim.hs
Created June 18, 2020 11:13
Asterius Haskell exported function issue: difference between ahc-cabal+ahc-dist and ahc-link
{-# OPTIONS_GHC -Wall -ddump-to-file -ddump-rn -ddump-foreign -ddump-stg -ddump-cmm-raw -ddump-asm #-}
module AsteriusPrim
( emptyJSString,
concatJSString,
indexJSString,
toJSString,
fromJSString,
emptyJSArray,
concatJSArray,
@acrylic-origami
acrylic-origami / A.hs
Created January 5, 2020 05:37
Minimal example of frontend plugin vs. regular GHC API usage
-- In subdirectory `target/A.hs`
module A where
@acrylic-origami
acrylic-origami / IxKotlin.kt
Last active February 14, 2019 02:59
Rx operator implementations from the five major classes outlined in https://lam.io/writing/ReactiveX using Kotlin reactive channels
import kotlin.collections.*
import org.reactivestreams.*
import kotlinx.coroutines.channels.*
import kotlinx.coroutines.reactive.*
import kotlinx.coroutines.*
import kotlin.coroutines.*
@ExperimentalCoroutinesApi
fun <T, U> Publisher<T>.debounce(timeout: Long, ctx: CoroutineContext) = GlobalScope.publish(ctx) {
var idx = 0;
@acrylic-origami
acrylic-origami / CovariantThisInInterface.php
Last active June 22, 2018 02:59
Why `this` in a contravariant position in an interface doesn't work out
<?hh // strict
interface Base {
public function foo(this $v): void;
}
final class Derived<T> implements Base {
public function bar(): void {}
public function foo(this $v): void {
$v->bar(); // an `OtherDerived` here would be unwelcome.
}
}
@acrylic-origami
acrylic-origami / ClassnameContravariantWrapperViolation.php
Created January 6, 2017 19:04
A contravariant variation of #7585 that doesn't allow a violation.
<?hh // strict
<<__ConsistentConstruct>>
abstract class ConWrapper<-T> {
public function __construct() {}
abstract public function act(T $v): void;
}
class ConcreteWrapper extends ConWrapper<OtherBase> {
public function act(OtherBase $v): void {
$v->fn();
}
@acrylic-origami
acrylic-origami / Forever.php
Created January 5, 2017 16:54
Called using HH\Asio\join(new Forever()->loop()); in the top level
<?hh // strict
class Forever {
private ?Awaitable<?(mixed, int)> $hook = null;
public function __construct() {
}
public async function loop(): Awaitable<void> {
$generator = $this->sub();
await ($this->hook = $generator->next());
}
private async function sub(): \AsyncIterator<int> {