Skip to content

Instantly share code, notes, and snippets.

Avatar
🗣️
play stupid games / win stupid prizes

Patrick Thomson patrickt

🗣️
play stupid games / win stupid prizes
View GitHub Profile
View ana.hs
#!/usr/bin/env cabal
{- cabal:
build-depends:
, base
, recursion-schemes > 5
, free
, comonad
-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE LambdaCase #-}
View lens.md

A Quick and Dirty Lens primer

Why does Lens exist? Well, Haskell records suck, for a number of reasons. I will enumerate them using this sample record.

data User = User { login    :: Text
                 , password :: ByteString
                 , email    :: Text
                 , created  :: UTCTime
                 }
View a11s.py
def abbrevify(word):
assert(len(word) >= 4)
num = len(word) - 2
return word[0] + str(num) + word[-1]
results = {}
for word in open('/usr/share/dict/words'):
word = word.strip()
if len(word) >= 4 and word.islower():
View breaks.diff
diff --git a/PLAN.org b/PLAN.org
index a79dafc..df34532 100644
--- a/PLAN.org
+++ b/PLAN.org
@@ -30,5 +30,6 @@ So how are we gonna do messages, too? Presumably there should be a status bar on
sidebar, +status bar, and body+
generalize the (Reader (BChan x)) and (Reader (MVar x)) and whatever with some unified Pipe interface
+prevent crashes by implementing valid, occupied :: Position -> Canvas -> Bool
slurp in some enemies
View either.swift
enum Either<A, B> {
case Left(A)
case Right(B)
}
func isLeft<A,B>(it : Either<A,B>) -> Bool {
switch it { case .Left: return true; case .Right: return false }
}
func isRight<A,B>(it : Either<A,B>) -> Bool {
View fused-effects-1.1-benchmarks
benchmarked Error/Either
time 24.22 μs (22.36 μs .. 26.34 μs)
0.983 R² (0.970 R² .. 0.998 R²)
mean 22.90 μs (22.65 μs .. 23.36 μs)
std dev 1.045 μs (590.7 ns .. 1.930 μs)
variance introduced by outliers: 24% (moderately inflated)
benchmarked Error/Identity/Church.ErrorC
time 9.092 ms (8.772 ms .. 9.300 ms)
0.995 R² (0.990 R² .. 0.998 R²)
View fused-effects-1.0-benchmarks
benchmarked Error/Either
time 48.08 μs (47.20 μs .. 49.37 μs)
0.994 R² (0.989 R² .. 0.999 R²)
mean 47.06 μs (46.60 μs .. 47.64 μs)
std dev 1.740 μs (1.034 μs .. 2.432 μs)
variance introduced by outliers: 18% (moderately inflated)
benchmarked Error/Identity/Either.ErrorC
time 5.277 ms (4.860 ms .. 5.552 ms)
0.980 R² (0.969 R² .. 0.988 R²)
View hack.diff
diff --git i/summoner-cli/src/Summoner/Default.hs w/summoner-cli/src/Summoner/Default.hs
index 41dfaa6..6a25abe 100644
--- i/summoner-cli/src/Summoner/Default.hs
+++ w/summoner-cli/src/Summoner/Default.hs
@@ -29,12 +29,12 @@ import Relude.Extra.Enum (prev)
import Data.Time (getCurrentTime, toGregorian, utctDay)
import NeatInterpolation (text)
-import System.Directory (getHomeDirectory)
+import System.Directory (getHomeDirectory, doesFileExist)
View cast.hs
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
View Some.hs
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
module Data.Some
( Some (..)
, Some1 (..)
, Any