Skip to content

Instantly share code, notes, and snippets.

View bitemyapp's full-sized avatar
🐺
aroo

Chris A. bitemyapp

🐺
aroo
View GitHub Profile
@MaxGabriel
MaxGabriel / redis-yesod.md
Last active March 3, 2016 20:25
Connecting to Redis from Yesod

Connecting to Redis from Yesod

This is a quick run-through of how I connected to Redis from a Yesod site (which used the default scaffolding). There isn't much specific to Redis here, so this information should apply to connecting to any database or service from Yesod.

Background: Basics of Hedis

First, a brief intro of the basics of Hedis:

{-# LANGUAGE OverloadedStrings #-}
@ttuegel
ttuegel / haskell-mode-indent.md
Last active February 15, 2016 23:06
Indentation pains in haskell-mode for Emacs

Electric indentation for parentheses, brackets, braces, commas, semicolons...

This isn't an issue of what I want, but rather when I want it. haskell-mode knows how to indent these things correctly, but I had to turn off electric indentation in haskell-mode because it does stupid things the rest of the time.

Concretely, I want a haskell-mode that knows how to be electric when there's only one "right" choice and that doesn't do stupid things when there are multiple possibilities.

@jtobin
jtobin / foo.hs
Created February 15, 2016 21:39
Independence and Applicativeness
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE LambdaCase #-}
import Control.Applicative.Free
import Control.Monad
import Control.Monad.Free
import Control.Monad.Primitive
import System.Random.MWC.Probability (Prob)
import qualified System.Random.MWC.Probability as MWC
@sinelaw
sinelaw / binary.hs
Created February 3, 2016 08:39
Binary encode/decode of Fixed
-- run it like:
-- stack ghc --package criterion -- binary.hs -Wall -O2 && ./binary
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE BangPatterns #-}
module Main where
import Data.ByteString.Lazy (ByteString)
import Data.Binary
import Data.Fixed
@ekmett
ekmett / Categories.hs
Created January 29, 2016 21:11
UndecidableSuperClasses test case
{-# language KindSignatures #-}
{-# language PolyKinds #-}
{-# language DataKinds #-}
{-# language TypeFamilies #-}
{-# language RankNTypes #-}
{-# language NoImplicitPrelude #-}
{-# language FlexibleContexts #-}
{-# language MultiParamTypeClasses #-}
{-# language GADTs #-}
{-# language ConstraintKinds #-}
@raichoo
raichoo / semantickata.hs
Last active January 20, 2016 01:26
Mini programming language to implement the recursive `fact` function.
{-# LANGUAGE LambdaCase #-}
module Main where
import Control.Applicative (liftA2)
import Control.Monad.Reader
type Varname = String
type Env = [(Varname, Dom)]
data Dom
--
import Data.Map.Lazy
import Control.Lens
-- We wanted to traverse a structure, but not recompute the function for duplicate keys. And then we also needed cache.
-- It's probably tricky to unlens this.
traverseMemoOf :: (Ord a, Monad f) => Traversal s t a b -> (a -> f b) -> s -> f (t, ML.Map a b)
traverseMemoOf l f z =
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE OverloadedStrings #-}
module Data.Yaml.Extended (module Data.Yaml.Extended, lift) where
import Data.Aeson.Types
import qualified Data.Text as T
import Control.Monad.State.Strict (StateT, runStateT, unless, lift, get, modify)
import qualified Data.HashMap.Strict as HM (null, delete, keys)
import Data.List (intercalate)
@frasertweedale
frasertweedale / Grammar.hs
Last active December 12, 2015 07:44
Prism-based parser/printer experiment
-- This file is a parsing experiment
-- Copyright (C) 2015 Fraser Tweedale
--
-- This software is free software: you can redistribute it and/or modify
-- it under the terms of the GNU Affero General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
{-
DPLL from the textbook:
function DPLL(clauses, symbols, model ) returns true or false
if every clause in clauses is true in model then return true
if some clause in clauses is false in model then return false
P , value ← FIND-PURE-SYMBOL (symbols, clauses, model )
if P is non-null then return DPLL(clauses, symbols – P , model ∪ {P =value})
P, value ← FIND-UNIT-CLAUSE (clauses, model)
if P is non-null then return DPLL(clauses, symbols – P , model ∪ {P =value})