Skip to content

Instantly share code, notes, and snippets.

View jfischoff's full-sized avatar
™️
Jonathaning

Jonathan Fischoff jfischoff

™️
Jonathaning
View GitHub Profile
@jfischoff
jfischoff / gist:912bf2243f40d158ffa8
Created November 15, 2014 07:04
Printing field names with the new-vinyl branch of Vinyl
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE GADTs #-}
@jfischoff
jfischoff / gist:df07e95ed8c3bd432a0f
Last active August 29, 2015 14:09
An iso between Sing xs and Rec Sing xs
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE OverlappingInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
@jfischoff
jfischoff / gist:b2f8c60883f2cfd0b187
Created December 13, 2014 23:51
Use case for reflection non law abiding Eqs
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE StandaloneDeriving #-}
module Approx where
import Data.Reflection
import Data.Proxy
import Foreign.Storable
@jfischoff
jfischoff / gist:999abf4ac5e5dc516d3a
Created December 31, 2014 22:40
A mix of Vinyl style and SOP style
foldRRec :: forall f xs c a b p.
RecAll f xs c
=> p c
-> (forall x. c x => x -> a)
-> (a -> b -> b)
-> b
-> NP f xs
-> b
foldRRec p convert f z xs
= foldRRec' convert f z
data Edit a
= Insert a
| Delete a
| Same a
deriving (Show, Eq)
isSame :: Edit a -> Bool
isSame x = case x of
Insert {} -> False
Delete {} -> False
@jfischoff
jfischoff / latency.markdown
Created June 7, 2012 18:40 — forked from roman/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@jfischoff
jfischoff / shake-cabal
Created July 2, 2012 23:13
Some shake cabal stuff I don't need
mkPackageRule packageDir = do
desc <- parseCabalPackage packageDir
let version = show $ pkgVersion $ package desc
srcs = collectSrcs desc
dependencies = collectDeps desc
libPath = [str|cabal-dev/lib/libHS$packageDir$-$version$.a|]
want libPath
libPath *> \_ -> do
need $ srcs ++ dependencies
system' "cabal-dev" ["install", packageDir ++ "/", "--force-reinstalls",
@jfischoff
jfischoff / Partial.hs
Created July 10, 2012 17:24
Some ideas for dealing with partial functions for setting management
module Control.Monad.Error.Restricted.Partial where
import Control.Applicative
import Data.Foldable (asum)
import qualified Data.HashMap.Strict as H
import Control.Monad hiding (msum)
import Data.Hashable
import Data.Foldable
import Data.Traversable
import Data.Monoid
import Data.Maybe
@jfischoff
jfischoff / gist:4034291
Created November 7, 2012 20:41
Type Level Associative Array
{-# LANGUAGE PolyKinds, DataKinds, TemplateHaskell, TypeFamilies,
GADTs, TypeOperators, RankNTypes, FlexibleContexts, UndecidableInstances,
FlexibleInstances, ScopedTypeVariables, MultiParamTypeClasses,
OverlappingInstances, TemplateHaskell #-}
module Oxymoron.Regions.TAssociativeArray where
import Data.Singletons
singletons [d| data AssocArray a b = AssocArray [(a, b)] |]
type instance ('AssocArray xs) :==: ('AssocArray ys) =