Skip to content

Instantly share code, notes, and snippets.

@joshcough
joshcough / ip1.hs
Created March 3, 2016 16:12 — forked from llelf/ip1.hs
{-# LANGUAGE GADTs, ConstraintKinds, Rank2Types, ImplicitParams #-}
data Rec fields where
Rec :: fields => Rec fields
infixr 1 ?
(?) :: Rec fields -> (fields => r) -> r
Rec ? e = e
record :: Rec (?a :: Int, ?b :: String)
@joshcough
joshcough / springer-free-maths-books.md
Created December 28, 2015 19:16 — forked from bishboria/springer-free-maths-books.md
Springer have made a bunch of maths books available for free, here are the direct links
@joshcough
joshcough / debug.hs
Last active August 29, 2015 14:26 — forked from pchiusano/debug.hs
Debugging trick in Haskell
module Foo where
import Debug.Trace
traceByteString :: String -> ByteString -> ByteString
traceByteString msg b | traceShow b False = undefined
traceByteString msg b = b

This is material to go along with a 2014 Boston Haskell talk.

We are going to look at a series of type signatures in Haskell and explore how parametricity (or lack thereof) lets us constrain what a function is allowed to do.

Let's start with a decidedly non-generic function signature. What are the possible implementations of this function which typecheck?

wrangle :: Int -> Int
module Infer where
import Control.Monad.State
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
data Var = V {-# UNPACK #-} !Int (Maybe String)
data HM = HM
{ nextVar :: {-# UNPACK #-} !Int
@joshcough
joshcough / CoreLexer.x
Last active August 29, 2015 14:08 — forked from dagit/CoreLexer.x
{
{-# OPTIONS -w #-}
module CoreLexer
( Alex(..)
, AlexPosn(..)
, Token(..)
, alexMonadScan
, runAlex
, alexGetInput
) where