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:
I hereby claim:
To claim this, I am signing this object:
| --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 | |
| --- |
| -- | 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 |
| 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 ) |
| {-| 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] |
| {-# LANGUAGE ConstraintKinds #-} | |
| {-# LANGUAGE DataKinds #-} | |
| {-# LANGUAGE FlexibleContexts #-} | |
| {-# LANGUAGE FlexibleInstances #-} | |
| {-# LANGUAGE GADTs #-} | |
| {-# LANGUAGE KindSignatures #-} | |
| {-# LANGUAGE OverlappingInstances #-} | |
| {-# LANGUAGE OverloadedStrings #-} | |
| {-# LANGUAGE PolyKinds #-} | |
| {-# LANGUAGE TypeFamilies #-} |
| # 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. |
| {-# LANGUAGE DataKinds #-} | |
| {-# LANGUAGE GADTs #-} | |
| {-# LANGUAGE PolyKinds #-} | |
| {-# LANGUAGE TypeFamilies #-} | |
| {-# LANGUAGE TypeOperators #-} | |
| module Foo where | |
| import Prelude hiding (Bool(..), not) |
| {-# 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 |
| {-# LANGUAGE DataKinds #-} | |
| {-# LANGUAGE GADTs #-} | |
| {-# LANGUAGE TypeFamilies #-} | |
| module GADTS where | |
| -- Some universe of types | |
| data Universe = A | |
| | B |