Skip to content

Instantly share code, notes, and snippets.

View ekmett's full-sized avatar
🤞

Edward Kmett ekmett

🤞
View GitHub Profile
@ekmett
ekmett / Cursed.hs
Last active September 23, 2022 16:35
backtracking "effects" with constraint kinds generically
#!/usr/bin/env cabal
{- cabal:
build-depends: base, constraints, ghc-prim
-}
{-# language AllowAmbiguousTypes, ConstrainedClassMethods, ConstraintKinds,
DefaultSignatures, FlexibleInstances, ImplicitParams, RankNTypes,
ScopedTypeVariables, TypeApplications, TypeFamilies, UndecidableSuperClasses #-}
import Control.Applicative
import Control.Concurrent.MVar
@ekmett
ekmett / lens.rs
Created July 24, 2022 20:26
lenses for rust don't have to be an inference nightmare
#![allow(non_camel_case_types)]
// type-inferrable lenses for rust can exist
// the bokeh of a lens is the stuff that is out of focus.
// this trait describes how given the lens as context, and a bokeh
// you can reassemble the result.
pub trait Bokeh<C,B> {
type T;
@ekmett
ekmett / wordle.hs
Last active January 25, 2022 06:38
rough initial wordle guess calculator
{-# language BlockArguments, TupleSections #-}
import Data.Array
import Data.Foldable
import Data.Char
import Prelude as P
type Pattern = Int
-- each pattern is an equivalence class of words, basically a color pattern.
aahed
aalii
aargh
aarti
abaca
abaci
aback
abacs
abaft
abaka
aback
abase
abate
abbey
abbot
abhor
abide
abled
abode
abort
@ekmett
ekmett / bone-weary.txt
Created January 5, 2022 20:21
An old cooperatively generated short story chapter using GPT-3
You rolled out of bed and stretched your lazy bones and looked over at the clock. You're late to work.
Ever since western civilization figured out that necromancy was an easy path to a cheap labor force that didn't need to be fed, life, or rather unlife, has been going downhill. Fortunately, summoning rituals are too expensive, so the world isn't literally going to hell, yet.
You stumbled over to the bathroom shower, and shut the door. You don't have eyes any more, so there's no real point to turning on the lights. No real point to anything really. It's not like I have any other choice.
"Hey Suzy…" you hear from the bathroom door. "Are you in there?"
You groggily look around the room and look over at the door. There is no one in the bathroom.
@ekmett
ekmett / codensity-yield
Created June 8, 2011 18:40
Yield: Mainstream Delimited Continuations via Codensity
module Yield where
-- Cleaned up version of Yield: Mainstream Delimited Continuations by Roshan James and Amr Sabry from TPDC 2011
import Data.Traversable
import Control.Monad.Trans
import Control.Monad.Free
import Control.Monad.Codensity
import Control.Comonad.Trans.Store
@ekmett
ekmett / IndicesAndLevels.hs
Last active August 4, 2021 18:27
a pragmatic mix of de bruijn indices and levels
{-# language PolyKinds #-}
{-# language BlockArguments #-}
{-# language AllowAmbiguousTypes #-}
{-# language StrictData #-}
{-# language DerivingStrategies #-}
{-# language GeneralizedNewtypeDeriving #-}
{-# language TypeApplications #-}
{-# language BangPatterns #-}
{-# language NPlusKPatterns #-}
{-# language TypeFamilies #-}
@ekmett
ekmett / mihaescu.doc
Created July 28, 2021 06:00
Notes on Catenable Deques - Tarjan & Mihaescu
COS 528 Notes on Catenable Deques
Fall 03 in Pure LISP
HO1
Data structure devised by Radu Mihaesau and Robert Tarjan 8/2003. See also:
H. Kaplan and R.E. Tarjan, “Purely functional, real-time deques with catenation,” J. Assoc. Comput. Mach. 46 (1999), 577-603.
H. Kaplan, C. Okasaki and R.E. Tarjan, “Simple confluently persistent catenable lists,” SIAM J. Comput. 30 (2000), 965-977.
@ekmett
ekmett / ProxyT.hs
Created June 17, 2021 04:51
When functional dependencies don't
{-# Language FlexibleInstances #-}
{-# Language MultiParamTypeClasses #-}
{-# Language FlexibleContexts #-}
{-# Language UndecidableInstances #-}
{-# Language DeriveTraversable #-}
{-# Language NoStarIsType #-}
{-# Language StandaloneKindSignatures #-}
{-# Language RoleAnnotations #-}
-- | Dysfunctional dependencies