Skip to content

Instantly share code, notes, and snippets.

View evincarofautumn's full-sized avatar

Jon Purdy evincarofautumn

View GitHub Profile
@evincarofautumn
evincarofautumn / Stlc.hs
Created May 1, 2022 05:39
Overcomplicated STLC
{-# Language
BlockArguments,
DataKinds,
DerivingStrategies,
GADTs,
InstanceSigs,
LambdaCase,
PatternSynonyms,
PolyKinds,
RankNTypes,
@evincarofautumn
evincarofautumn / STLC.hs
Created November 3, 2020 04:05 — forked from gallais/STLC.hs
STLC
{-# LANGUAGE GADTs #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE PolyKinds #-}
module STLC where
-- Defining type and the corresponding singletons
@evincarofautumn
evincarofautumn / Existentials.hs
Last active September 6, 2020 05:08
Existentials in C# (Haskell Translation)
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
import Data.Function (fix)
import Data.IORef
-- INPUT: void M(ICounter)
-- Usage: m intCounter
m :: ICounter -> IO ()
@evincarofautumn
evincarofautumn / debug.ktn
Created August 10, 2020 19:15
Kitten Debug Trait
-_
trait debug<T> (T -> debug::Repr);
about debug<T>:
kitten::docs:
"""
Produce a debugging representation (`debug::Repr`) of a value.
For uninspectable types such as functions, use `debug::opaque`.
@evincarofautumn
evincarofautumn / shelter.md
Last active July 29, 2020 19:48
Programming Language Idea Shelter

Programming Language Idea Shelter

This is a list of notations and semantics I’ve wanted to use or have used in toy programming languages that I think are particularly nice but rare, and that I’d like to see in more languages. If you’re a PL dev and you fall in love with one, adopt it and let me know!

Unary Relational Range Operators

Most languages use the standard relational operators for comparisons (&gt;, &lt;, /&gt;=, /&lt;=/=&lt;, =/==/===, /!=//=/&lt;&gt;), but these are almost always presented as binary operators for comparing two values. Some languages (of which Python is the most notable) include “chained” comparisons like a &lt;= b &lt; c, meaning a &lt;= b and b &lt; c (but with b only evaluated for its side effects once, that is, (lambda x: a &lt;= x and x &lt; c)(b)). Some languages also allow unary versions of these operators, but they rarely denote anything related to comparisons. Some languages such as Haskell allow arguments to be omitted from operators via operator sections, denot

@evincarofautumn
evincarofautumn / TypedTypechecking.hs
Created June 24, 2020 23:23
Strongly Typed Typechecker for Simply Typed Lambda Calculus in Haskell
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
// Uninhabited type, value-kinded
type Void {}
// or:
// type synonym Void as type (VOID);
// Uninhabited type, poly-kinded
type VOID<K> as K {}
// or (wibbles):
// type VOID as <K> K {}
// type<K> VOID as K {}
#include <iostream>
#include <optional>
#include <vector>
using namespace std;
template<template<typename A> typename F>
struct Alternative {
template<typename A>
static F<A> empty();
@evincarofautumn
evincarofautumn / Roommates.hs
Last active June 12, 2020 21:54
Heuristic stable roommates with k-person rooms by approval voting
import Data.Ord (Down(..), comparing)
import Data.List (permutations, sortBy)
import Data.Maybe (listToMaybe)
import qualified Data.Set as Set
-- | A matrix of approval votes. @forall (a :: 'Approvals'). a !! i !! j@
-- is the number of approval votes that person @i@ awarded to person @j@.
type Approvals = [[Int]]
-- | List of list of indices representing a partition of a list. Invariant:
@evincarofautumn
evincarofautumn / OneOfMany.hs
Last active September 15, 2019 07:31
Poll asyncs until any fails or all return and only one succeeds
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE ScopedTypeVariables #-}
oneOfMany :: forall a. [Async (Maybe a)] -> IO (Either SomeException (Maybe a))
oneOfMany asyncs = loop
where
loop :: IO (Either SomeException (Maybe a))
loop = do
statuses <- for asyncs poll