Skip to content

Instantly share code, notes, and snippets.

@jnape
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
jnape / Convolution.java
Created Jul 23, 2020
parallel / sequential convolution generalized to any algebraic ring
View Convolution.java
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
jnape / pom.xml
Created Apr 16, 2019
mnichols test pom
View pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>mnichols</groupId>
<artifactId>lambda-spike</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>lambda-spike</name>
<description>examples</description>
@jnape
jnape / HListMapper.java
Created Feb 25, 2018
Mapping the slots of an HList
View HListMapper.java
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
jnape / SizedIterable.java
Created Jan 24, 2018
Dependently-typed Iterable
View SizedIterable.java
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
jnape / Spike.java
Created Dec 27, 2017
Type-level encoding and optimization of tail recursive functions in Java with Lambda
View Spike.java
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;
View SetIsNotAFullyFaithfulFunctor.java
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;
}