Skip to content

Instantly share code, notes, and snippets.

View plaidfinch's full-sized avatar

plaidfinch plaidfinch

View GitHub Profile
@PkmX
PkmX / loeb.md
Last active January 9, 2019 15:59
Löb with error handling

Löb with error handling

löb is a well-known function in Haskell for implementing spreadsheet-like behaviors and tying the knot. It is defined as:

loeb :: Functor f => f (f a -> a) -> f a
loeb fs = xs
  where xs = fmap ($ xs) fs
@stelleg
stelleg / hm_scott.lhs
Last active July 4, 2016 10:42
Hindley Milner + Scott Encoding Musings
Sometimes it would be nice if a type system could automatically "do it's best"
to restrict what a value will be. For example, the type `Bool` is the compiler
saying the value will either be `True` or `False`, but it doesn't know which.
What we want is the compiler to be able to be precise when possible, so instead
of always saying `Bool` (or "I don't know"), it could say `True`, `False`, or
`Bool`. This gist shows how Hindley Milner already has this capability that can
be exercised by using Church or Scott encodings of simple data types.
> {-# LANGUAGE RankNTypes #-}
> import qualified Data.Maybe as M
@gatlin
gatlin / comonadic_evaluator.hs
Last active August 29, 2015 14:17
Perhaps comonadic fix points can be useful in compilers and interpreters?
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveTraversable #-}
import Prelude hiding (take)
import Control.Comonad
import Control.Comonad.Sheet
import Data.Foldable
import Data.Traversable
@sinelaw
sinelaw / tailor.sh
Last active January 2, 2016 04:06
In-place tail: prints the last output line of a command, overriding it in-place
#!/bin/bash -eu
LOG_FILE=$1
SB="stdbuf -i0 -oL"
shift
tput sc
$@ 2>&1 | $SB tee $LOG_FILE | $SB cut -c-$(tput cols) | $SB sed -u 's/\(.\)/\\\1/g' | $SB xargs -0 -d'\n' -iyosi -n1 bash -c 'tput rc;tput el; printf "\r%s" yosi'
EXIT_CODE=${PIPESTATUS[0]}
tput rc;tput el;printf "\r" # Delete the last printed line
exit $EXIT_CODE
@lambdageek
lambdageek / Bidirectional.hs
Created March 17, 2015 22:58
Bidirectional typechecking using GADTs and DataKinds
{-# LANGUAGE DataKinds, KindSignatures, GADTs, StandaloneDeriving, TypeFamilies #-}
module Bidirectional where
import Control.Applicative
import Control.Monad (when)
----------------------------------------
-- 'Flow d a' is like 'Maybe a' except the type index 'd' says whether
-- we're given a value or whether we want one.
{-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving, TemplateHaskell, FlexibleInstances #-}
{-# OPTIONS_GHC -Wall -fno-warn-missing-signatures #-}
module QQAST where
import Control.Applicative
import Control.Exception
import Control.Monad.State
import Data.Data (Data)
import Data.Generics (extQ)
import Data.IORef
@neel-krishnaswami
neel-krishnaswami / re.ml
Created November 7, 2013 12:20
Implementation of DFA-based regexp matching using Antimirov derviatives
type re = C of char | Nil | Seq of re * re | Bot | Alt of re * re | Star of re
let rec null = function
| C _ | Bot -> false
| Nil | Star _ -> true
| Alt(r1, r2) -> null r1 || null r2
| Seq(r1, r2) -> null r1 && null r2
module R = Set.Make(struct type t = re let compare = compare end)
let rmap f rs = R.fold (fun r -> R.add (f r)) rs R.empty
@dergachev
dergachev / GIF-Screencast-OSX.md
Last active May 17, 2024 02:53
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@awto
awto / DoubleCont.hs
Created November 15, 2012 17:51
shift/reset via double CPS transform
module DoubleCont where
import Control.Monad.Cont
reset :: ContT a (ContT r m) a -> ContT b (ContT r m) a
reset e = ContT $ \k ->
ContT $ \m ->
runContT (runContT e return)
(\r -> runContT (k r) m)
@sunilnandihalli
sunilnandihalli / binary-zipper.clj
Created August 26, 2011 07:16
learning to use zippers..
(def s {:l {:l {:val 4}
:r {:val 6}
:val 10}
:r {:val 20
:l {:val 11
:l {:val 3}
:r {:val 8}}
:r {:val 9
:l {:val 2}
:r {:val 7}}}