Skip to content

Instantly share code, notes, and snippets.

View chrisdone-artificial's full-sized avatar

Chris Done chrisdone-artificial

View GitHub Profile
{-# LANGUAGE KindSignatures, BlockArguments #-}
{-# language GADTs, LambdaCase, GeneralizedNewtypeDeriving #-}
import Control.Monad.Free
import Control.Applicative.Free
import qualified Data.ByteString as S
import qualified Data.ByteString.Char8 as S8
import Data.Functor.Identity
import Data.ByteString (ByteString)
import qualified Data.Map as Map
import Data.Map (Map)
{-# LANGUAGE KindSignatures #-}
{-# language GADTs, LambdaCase, GeneralizedNewtypeDeriving #-}
import Control.Monad.Free
import Control.Applicative.Free
import qualified Data.ByteString as S
import qualified Data.ByteString.Char8 as S8
import Data.Functor.Identity
import Data.ByteString (ByteString)
import qualified Data.Map as Map
import Data.Map (Map)
@chrisdone-artificial
chrisdone-artificial / liquid haskell.hs
Created January 3, 2026 16:26
free/alloc M but no cigar
-- needs to be a `M i o a', but almost there. LH is difficult (bad docs, bad errors, changing syntax)
{-# LANGUAGE GADTs #-}
{-# OPTIONS_GHC -fplugin=LiquidHaskell #-}
{-# language GeneralizedNewtypeDeriving, DeriveFunctor #-}
{-@ LIQUID "--prune-unsorted" @-}
import Control.Monad.State
import Data.Set qualified as Set
@chrisdone-artificial
chrisdone-artificial / liquid haskelld.hs
Last active January 2, 2026 12:42
read file, liquid haskell'd
{-# OPTIONS_GHC -fplugin=LiquidHaskell #-}
{-# language OverloadedStrings, BangPatterns #-}
import Data.Word
import Foreign.Ptr
import Foreign.C.Types
import Foreign.Marshal.Alloc
import System.Posix.IO.ByteString
import System.Posix.Types
main :: IO ()
@chrisdone-artificial
chrisdone-artificial / todo.hell
Last active December 3, 2025 20:11
todo.hell
data Todo = Todo {
id :: Text,
created :: UTCTime,
title :: Text,
description :: Text,
priority :: Int
}
data Command
= Add Main.Todo
@chrisdone-artificial
chrisdone-artificial / fp.yaml
Last active November 7, 2025 13:37
Functional Pearls weekly discussion job
name: Create Functional Pearl discussion weekly
on:
schedule:
- cron: "0 12 * * 5" # 5 = Friday (12:00 UTC)
workflow_dispatch:
jobs:
create-discussion:
runs-on: ubuntu-latest
@chrisdone-artificial
chrisdone-artificial / 0readme.md
Last active November 7, 2025 09:49
Nondeterminism with Referential Transparency in Functional Programming Languages

The one using a proper PRNG is more typical.

The other one is more like the paper intended, I think, which is to literally run a side-effect on every call to choice (lazy I/O), which is what this does (modulo buffered reads).

data Opts = Opts {
startDate :: Text,
step :: Text
}
options =
(\startDate step -> Main.Opts { startDate, step })
<$> Options.strOption (Option.long "start-date" <> Option.help "Starting date in 2025-01-24 format.")
<*> Options.strOption (Option.long "step" <> Option.help "How many days to add each line.")
@chrisdone-artificial
chrisdone-artificial / background.js
Last active October 10, 2025 13:11
temp-link-opener
// Create the context menu item when the extension is installed
browser.contextMenus.create({
id: "open-link-temporarily",
title: "Open Link temporarily",
contexts: ["link"]
});
// Track tabs that should be auto-closed
const tempTabs = new Map();
newtype T1 t a = T1 { unT1 :: forall e. t e a }
deriving instance (forall e. Functor (t e)) => Functor (T1 t)
instance (forall e. Applicative (Either e)) => Applicative (T1 Either) where
pure x = T1 (pure x)
(<*>) f x = T1 (unT1 f <*> unT1 x)
instance (forall e. Monad (Either e)) => Monad (T1 Either) where
(>>=) m f = T1 (unT1 m >>= unT1 . f)