Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am jacobstanley on github.
  • I am jacobstanley (https://keybase.io/jacobstanley) on keybase.
  • I have a public key whose fingerprint is 134E 69FE D660 1130 BFBE 29F7 E5F5 4903 3637 6192

To claim this, I am signing this object:

import qualified System.Console.Concurrent as Concurrent
trace :: [Char] -> a -> a
trace string expr =
unsafePerformIO $ do
traceIO string
return expr
traceIO :: [Char] -> IO ()
traceIO string = do
@jacobstanley
jacobstanley / 1-Usage.hs
Last active August 12, 2019 22:01
Quasi-quoter which captures source
-- Quoter unfortunately need to be in another file due to GHC staging restrictions
import Quoter
foo :: ParsedExpr
foo =
[expr| Var "salads" |]
-- foo =
ParsedExpr {parsedSource = " Var \"salads\" ", parsedExpr = Var "salads"}
@jacobstanley
jacobstanley / Property.purs
Created November 17, 2016 01:28
Property as a Monad
prop_foo :: Property ()
prop_foo = do
x <- forAll $ elements ["a", "b", "c"]
y <- forAll $ chooseInt 0 10
guard $ not (x == "a" && y == 5) -- works like (==>) from QuickCheck
..
@jacobstanley
jacobstanley / simplify-type.hs
Last active August 11, 2016 07:50
Simplify parser return types
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE PartialTypeSignatures #-}
@jacobstanley
jacobstanley / ec2.md
Last active December 1, 2016 23:47
EC2 Instances

Ordered by vCPU

Instance Type vCPU Memory (GiB) Storage (GB) SSD Drives Network Perf. Processor Clock (GHz) AVX AVX2 Turbo EBS Opt. Enhanced Network
t1.micro 1 0.613 - - EBS Only Very Low ? ? - - - - -
t2.nano 1 0.5 - - EBS Only Low Intel Xeon family Up to 3.3 Yes - Yes - -
t2.micro 1 1 - - EBS Only Low to Moderate Intel Xeon family Up to 3.3 Yes - Yes - -
m1.small 1 1.7 160 - 1 x 160 Low ?
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE InjectiveTypeFamilies #-}
class Bonkers b where
type Bonkers1 b = b1 | b1 -> b
type Bonkers2 b = b2 | b2 -> b
bonkersFrom :: Bonkers1 b -> Bonkers2 b
bonkers :: Bonkers b => Bonkers1 b -> Bonkers2 b
@jacobstanley
jacobstanley / dissect-reassoc.hs
Last active March 12, 2016 02:39
Generic deconstruction of product types to tuples
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
@jacobstanley
jacobstanley / show-gadts.hs
Created March 6, 2016 00:40
Showing GADTs
data Parser a where
Val :: Show a => a -> Parser a
Cat :: Parser a -> Parser b -> Parser (a, b)
instance Show (Parser a) where
showsPrec p x =
showParen (p > 10) $
case x of
Val n ->
showString "Val " .
@jacobstanley
jacobstanley / multi-ghc.md
Created February 16, 2016 23:17
Installing Multiple GHC Versions

Installing Multiple GHC Versions

Use these instructions if you want to run multiple versions of GHC side-by-side.

This setup doesn't have GHC on the PATH by default, and uses g to cycle between available versions.

Install GHC 7.8.4

$ wget https://www.haskell.org/ghc/dist/7.8.4/ghc-7.8.4-x86_64-apple-darwin.tar.xz