Skip to content

Instantly share code, notes, and snippets.

jnape / Scheduling.hs
Created Mar 13, 2021
Cooperative multitasking in haskell
View Scheduling.hs
{-# LANGUAGE RankNTypes #-}
module Scheduling where
newtype Fiber f a = Fiber (f (Maybe (Maybe a, Fiber f a)))
noop :: Applicative f => Fiber f a
noop = Fiber $ pure Nothing
singleton :: Applicative f => f (Maybe a) -> Fiber f a
View coproduct.h
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <optional>
#include <variant>
#include <any>
template<template<typename, typename> typename CP, typename A, typename B, typename R, template<typename> typename F> concept Coproduct2 =
requires (CP<A,B> cp, F<R(A)> f, F<R(B)> g) {
jnape /
Created Jul 23, 2020
parallel / sequential convolution generalized to any algebraic ring
static interface CommutativeSemigroup<A> extends Semigroup<A> {
static interface CommutativeMonoid<A> extends CommutativeSemigroup<A>, Monoid<A> {
static interface Abelian<A> extends CommutativeMonoid<A> {
A inverse(A a);
static interface Ring<A> {
Abelian<A> addition();
Monoid<A> multiplication();
View lambda.cpp
#include <thread>
#include <iostream>
#include <functional>
#include <algorithm>
#include <numeric>
#include <any>
namespace {
struct __ {};
struct ___ {};
View suffering.h
#include <thread>
#include <iostream>
#include <functional>
template<typename T> using Id = T&;
template<typename A, typename B>
struct Phi {
template<typename R>
R match(std::function<R(A)>, std::function<R(B)>) {
jnape / pom.xml
Created Apr 16, 2019
mnichols test pom
View pom.xml
<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
jnape /
Created Feb 25, 2018
Mapping the slots of an HList
package com.jnape.palatable.lambda.adt.hlist;
import com.jnape.palatable.lambda.adt.hlist.HList.HCons;
import com.jnape.palatable.lambda.adt.hlist.HList.HNil;
import java.util.function.Function;
import static com.jnape.palatable.lambda.adt.hlist.HList.cons;
import static com.jnape.palatable.lambda.adt.hlist.HList.nil;
import static com.jnape.palatable.lambda.adt.hlist.HList.singletonHList;
jnape /
Created Jan 24, 2018
Dependently-typed Iterable
package example;
import com.jnape.palatable.lambda.functions.builtin.fn2.Cons;
import com.jnape.palatable.lambda.functions.builtin.fn2.Snoc;
import java.util.Iterator;
import static com.jnape.palatable.lambda.functions.builtin.fn3.FoldLeft.foldLeft;
import static example.SizedIterable.Nat.s;
import static example.SizedIterable.Nat.stringify;
jnape /
Created Dec 27, 2017
Type-level encoding and optimization of tail recursive functions in Java with Lambda
package spike;
import com.jnape.palatable.lambda.adt.choice.Choice2;
import com.jnape.palatable.lambda.adt.coproduct.CoProduct2;
import com.jnape.palatable.lambda.functions.Fn1;
import com.jnape.palatable.lambda.functions.Fn2;
import com.jnape.palatable.lambda.functions.builtin.fn2.Cons;
import com.jnape.palatable.lambda.functor.Bifunctor;
import java.util.Iterator;
public static class SetIsNotAFullyFaithfulFunctor {
public static void main(String[] args) {
class Mod {
private final int mod;
private final int value;
Mod(int mod, int value) {
this.mod = mod;
this.value = value;