Skip to content

Instantly share code, notes, and snippets.

View aaronlevin's full-sized avatar

Aaron Levin aaronlevin

View GitHub Profile

Keybase proof

I hereby claim:

  • I am aaronlevin on github.
  • I am aaronlevin (https://keybase.io/aaronlevin) on keybase.
  • I have a public key whose fingerprint is 3900 0396 924C 9990 4912 94D3 FDD0 B4E9 9845 2EE5

To claim this, I am signing this object:

@aaronlevin
aaronlevin / free-monads.tpp
Created July 23, 2015 00:36
Free Monad talk @ Bento Miso
--title Rapid Prototyping in Haskell with Free Monads
--author Aaron Levin
--date today
--footer aaron levin (c) 2015 @ Bento Miso
--newpage
--center who?
* Aaron Levin
---
@aaronlevin
aaronlevin / complicated-paren-checker.hs
Last active June 24, 2016 16:57
Adventures in Point-Free, Arrowized Absurdity
-- | check for parens in a string, exiting early if the left paren count is -1. Fully point-free and
-- arrow-fied
-- It works as follows:
-- 1. use a monadic fold (foldM) with the Either monad to exit early
-- 2. take a list of methods that test if the count is -1, or the paren is '(', or the paren is ')'
-- 3. zip the list with another list that looks at the booleans and decides what functions they should
-- result in. if there are no parens, the functions just add 0 to the count
-- 4. sequence the monad actions (this will exit early if there is a Left present)
-- 5. fold over the functions in the Right branch with function composition
-- 6. at this piont we just want to apply the the resulting function in the Right branch to the current
@aaronlevin
aaronlevin / edit-distance.hs
Last active August 29, 2015 14:19
Edit-Distance Matrix For Levenshtein Distance Calculation
module Fun where
import Control.Arrow ((<<<), (***))
import Data.Matrix (getElem, mapCol, mapRow, Matrix, setElem, zero)
import Data.List (foldl')
-- | initialize the edit-distance matrix.
-- λ> initEditMatrix "sitting" "kitten"
-- ( 0 1 2 3 4 5 6 )
-- ( 1 0 0 0 0 0 0 )
@aaronlevin
aaronlevin / type-references.hs
Created April 16, 2015 15:40
Using type families to specify references depending on source
{-| we often have this problem wehere we get some data
from the database that refers to another piece of data.
For example, suppose we have an Order that referes to
a Customer and some Products. Do we represent it like this:
data Order = Order Customer [Product]
Or do we represent it like this:
data Order = Order UUID [UUID]
@aaronlevin
aaronlevin / free-cqrs.hs
Created April 10, 2015 21:02
Free CQRS
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE OverlappingInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
@aaronlevin
aaronlevin / 01-shell.nix
Last active February 22, 2016 17:57
Local/Project-based Environment Management Using Nix (with new Haskell NG infrastructure)
# Inspired by:
# http://stackoverflow.com/questions/29033580/how-do-i-use-the-new-haskell-ng-infrastructure-on-nixos
#
# The goal
#
# 1. my-project.cabal remains the source of required libraries/packages to build the project.
# Adding a new library involves updating my-project.cabal and then running cabal2nix . > 02-my-project.nix
#
# 2. ability to add non-haskell build / dev dependencies to our `shell.nix` that are not used at runtime.
# For example, maybe we want to use postgresql or redis during development.
@aaronlevin
aaronlevin / not.hs
Last active August 29, 2015 14:18
Answer to a question at our Intersections KW Meetup: http://www.meetup.com/Intersections-KW/events/221476419/
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Foo where
import Prelude hiding (Bool(..), not)
@aaronlevin
aaronlevin / 01-simplest-thing-that-works.hs
Last active August 30, 2019 02:49
Proxy Serialization Post
{-# LANGUAGE OverloadedStrings #-}
module SimpleThings where
import Control.Applicative ((<$>), (<*>))
import Control.Monad (mzero)
import Data.Aeson
import qualified Data.Aeson as A
-- | sum type containing all possible payloads
@aaronlevin
aaronlevin / patterns-not-matched.hs
Last active August 29, 2015 14:15
patterns not matched
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
module GADTS where
-- Some universe of types
data Universe = A
| B