Skip to content

Instantly share code, notes, and snippets.

View frasertweedale's full-sized avatar

Fraser Tweedale frasertweedale

View GitHub Profile
module Experiement where
import Data.Kind (Type)
import Data.Proxy (Proxy(..))
data VariantA
data VariantB
data VariantC
data Object (a :: Type) = Object

Keybase proof

I hereby claim:

  • I am frasertweedale on github.
  • I am frasertweedale (https://keybase.io/frasertweedale) on keybase.
  • I have a public key whose fingerprint is 5848 CE28 186B B469 C295 15E1 4B53 9052 4111 E1E2

To claim this, I am signing this object:

@frasertweedale
frasertweedale / Hungry.hs
Last active October 15, 2021 00:37
Why does this program consume 8.6G memory?
module Main where
import Control.Monad (replicateM)
import Data.Char (ord)
import Data.Foldable (for_)
import Data.List (foldl')
import Data.Word (Word)
import System.Environment (getArgs)
hash :: [Char] -> Word
@frasertweedale
frasertweedale / Experiment.hs
Last active October 6, 2021 21:45
length-indexed list experiment
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE MultiParamTypeClasses #-}
import Control.Applicative (Alternative(..))
import Data.Char (isDigit)
@frasertweedale
frasertweedale / SubsetsMatchingCondition.hs
Last active August 6, 2021 03:31
minimal subsets matching condition
module SubsetsMatchingCondition where
import Data.Maybe (mapMaybe)
data Cond a = Unsatisfied a | Satisfied a
deriving (Show)
-- | Construct *minimal* subsets that satisfy the
-- condition upon the monoidal fold. The monoidal
-- append must be "monotonic" for sensible results.
@frasertweedale
frasertweedale / bfpg-2021-03.md
Last active March 19, 2021 07:59
BFPG 2021-03 discussion ideas
@frasertweedale
frasertweedale / jss_alpn.java
Created October 6, 2020 04:06
JSS ALPN test
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.nio.charset.StandardCharsets;
import org.mozilla.jss.CryptoManager;
import org.mozilla.jss.InitializationValues;
import org.mozilla.jss.crypto.X509Certificate;
@frasertweedale
frasertweedale / LdapGssDemo.java
Created August 28, 2020 04:29
ldapjdk GSSAPI bind test program
import java.util.Hashtable;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.Callback;
import netscape.ldap.LDAPConnection;
import netscape.ldap.LDAPEntry;
import netscape.ldap.LDAPUrl;
class Main {
@frasertweedale
frasertweedale / errors.rs
Last active January 29, 2022 19:26
classy errors in rust
/* Composable errors via traits
A major challenge (among several) in error handling is how to deal with
disjoint error types produced by the libraries you use (as well as by
your own program) in a consistent and ergonomic way. Rust's `?` operator
improves the ergonomics of error handling, but it can only be used with
a single error type throughout a single function. Libraries define their
own error types and they don't know about each other, nor about the calling
program. So if we want to deal with errors from different libraries as
a single type (an sum or enum of the different underlying error types), we
@frasertweedale
frasertweedale / Workflow.hs
Last active May 20, 2020 01:22
workflow library
{-# LANGUAGE KindSignatures #-}
module Workflow where
import Data.Bool (bool)
data Workflow a r
= Decision a (Workflow a r) (Workflow a r)
| Guard a (Workflow a r)