Skip to content

Instantly share code, notes, and snippets.

View evincarofautumn's full-sized avatar

Jon Purdy evincarofautumn

View GitHub Profile
@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 / ImportBlocks.hs
Created August 1, 2019 17:38
ImportBlocks extension
-- Put some layout keyword after imports so their bodies can be formatted as blocks
import Data.Foldable where
asum
import Control.Concurrent where
forkIO
threadDelay
import Control.Concurrent.STM where
@evincarofautumn
evincarofautumn / concurrent-esolang.md
Last active May 6, 2019 05:41
Concurrent Esolang Idea

A minimal esoteric language in which execution semantically proceeds in lockstep with a fixed global clock on a “grid” of instructions.

Each grid cell may contain an instruction or an extension of an instruction (for multi-stream instructions), with an optional override slot that overrides the result of the instruction (if any). All streams are zero by default, and an instruction that produces no output semantically produces zero(s).

Each instruction has a consumption, the number of streams it consumes, and a production, the number of streams it produces; its width is the maximum of its consumption and production. It’s an error to schedule an instruction with the wrong width.

A stream is only 8 bits wide; if you want multi-byte data, you must spread it across multiple streams.

Grammar

@evincarofautumn
evincarofautumn / puzzle.pl
Last active December 5, 2018 03:36
Logic Puzzle
% Using integer constraint programming
:- use_module(library(clpfd)).
% Encoding the solution as a predicate
solution(Pairs, BirdPendant, WarMedal, Diamond, Ring, Vs) :-
% List the variables to solve
Table = [People, Colors, Places, Drinks, Heirlooms],
Colors = [Purple, Red, Green, White, Blue],
Places = [Dabovka, Karnaca, Baleton, Dunwall, Fraeport],
@evincarofautumn
evincarofautumn / 200-proof.hs
Created November 29, 2018 03:23
Toying around with proofy-lookin Haskell code
{-# LANGUAGE
BangPatterns,
DataKinds,
GADTs,
KindSignatures,
PolyKinds,
ScopedTypeVariables,
TypeFamilies,
TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TypeFamilies #-}
module Main where
data Exp (p :: Phase)
= (HasInfix p ~ 'True) => Infix (Anno p) !Op (Exp p) (Exp p)
| (HasStack p ~ 'False) => Call (Anno p) (Exp p) (Exp p)
@evincarofautumn
evincarofautumn / like-seriously.txt
Created April 30, 2018 07:56
Permutations of “no stop dude literally like seriously fuck”
no stop dude literally like seriously fuck
stop no dude literally like seriously fuck
dude stop no literally like seriously fuck
stop dude no literally like seriously fuck
dude no stop literally like seriously fuck
no dude stop literally like seriously fuck
literally dude stop no like seriously fuck
dude literally stop no like seriously fuck
dude stop literally no like seriously fuck
literally stop dude no like seriously fuck
@evincarofautumn
evincarofautumn / Nonad.hs
Created February 22, 2018 21:13
Monadicity Polymorphism
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
import Data.Functor.Identity
import Prelude hiding (Functor(..), Applicative(..), Monad(..), map)
@evincarofautumn
evincarofautumn / matmul.ktn
Created January 28, 2018 04:24
Vectorized matrix multiplication in Kitten
define square_matrix_multiply
<N as Size>
(Array<(N * N), Float>, Array<(N * N), Float>
-> Array<(N * N), Float>)
{
-> left, right;
// static::<N> lifts the value of the static constant N to runtime.
if (static::<N> >= 256):
512
@evincarofautumn
evincarofautumn / ComposeDo.hs
Created November 1, 2017 00:30
Compositional do notation
{-# LANGUAGE RebindableSyntax #-}
import Control.Arrow
import Control.Monad
import Data.Function
import Data.Monoid
import Prelude
import System.IO
main :: IO ()