Skip to content

Instantly share code, notes, and snippets.

View evincarofautumn's full-sized avatar

Jon Purdy evincarofautumn

View GitHub Profile

Grammar of Kitten

This is an annotated EBNF grammar of the latest rewrite of Kitten. Items marked with a dagger (†) are explained in the surrounding prose, not in EBNF.

Source Locations

The source column of a token is the offset to its first character within the line in which it appears. The indentation of a line is the source column of the first token in the line. Tab characters are illegal.

Layout

@evincarofautumn
evincarofautumn / Stlc.hs
Created May 1, 2022 05:39
Overcomplicated STLC
{-# Language
BlockArguments,
DataKinds,
DerivingStrategies,
GADTs,
InstanceSigs,
LambdaCase,
PatternSynonyms,
PolyKinds,
RankNTypes,
@evincarofautumn
evincarofautumn / InlineDoBind.md
Last active April 20, 2023 21:16
Thoughts on an InlineDoBind extension

Thoughts on an InlineDoBind extension

An expression beginning with a left arrow (<-) inside a do block statement is desugared to a monadic binding. This is syntactically a superset of existing Haskell, including extensions. It admits a clean notation that subsumes existing patterns and comes with few downsides.

Examples

do
  f (<- x) (<- y)
-- ===
@evincarofautumn
evincarofautumn / monoid.cpp
Last active May 1, 2021 11:22
Monoids in C++
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
// In Haskell, the Monoid typeclass is parameterised by only a type. Such a
// definition requires “newtype hacks” to produce different monoids on the same
// type. This definition is parameterised by both the type and the function, and
// as such can be used to define different monoids on the same type without any
// interference.
@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 / 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 #-}
@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 / RZip.hs
Last active August 11, 2020 18:12
Zip from end of list
rzipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
rzipWith f xs0 ys0 = loop 0 0 xs0 ys0
where
loop x y = curry \ case
(_:xs, _:ys) -> loop (succ x) (succ y) xs ys
(xs, []) -> done (x + length xs) y
([], ys) -> done x (y + length ys)
@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