Skip to content

Instantly share code, notes, and snippets.

@tranma
tranma / Snail.hs
Created September 15, 2012 19:27
Relations, Graphs and Trees
{-# LANGUAGE TupleSections, FlexibleInstances #-}
-- Manipulate graphs for metadata generation
-- WARNING: everything in here is REALLY REALLY REALLY SLOW
--
module Snail
( Rel(..)
, fromList, toList
, allR, differenceR, unionR, composeR, transitiveR
, transClosure
module Foo where
import Data.List
import Data.Ord
import Debug.Trace
-- | A binary relation.
type Rel a = a -> a -> Bool
type Dom a = [a]
@tranma
tranma / MatchDataCon.hs
Last active August 29, 2015 14:00
match on some data constructors, useful for writing smart constructors?
{-# LANGUAGE GADTs, DataKinds, KindSignatures, TemplateHaskell, QuasiQuotes #-}
module Foo (bar, Foo(..), SBool(..))
where
import Language.Haskell.TH
data SBool b where
STrue :: SBool True
SFalse :: SBool False
#!/bin/bash
DEV_DIR=$1
REPOS=("package1" "package2")
RED='\033[1;33m'
BLUE='\033[1;31m'
NC='\033[0m'
if [[ -z $DEV_DIR ]]
@tranma
tranma / setup.sh
Last active August 29, 2015 14:06
#!/bin/bash
REPOS=$(dirname $(pwd))
echo_color() {
local t=$1
INFO='\033[1;33m'
NC='\033[0m'
echo -e "${INFO}$t${NC}"
}
@tranma
tranma / TryAgainPipe.hs
Last active August 29, 2015 14:07
pipe that echoes stdin while ignoring any input it has seen before, but timeouts if user is taking too long, and offers a chance to try again
{-# LANGUAGE ExistentialQuantification #-}
import Control.Monad.Error
import Control.Monad.Trans.State.Strict
import Data.Time.Clock
import Pipes
import qualified Pipes.Prelude as P
import qualified Pipes.Lift as P
@tranma
tranma / MS.hs
Created October 14, 2014 01:42
squash StateTs that have the same monoid as state
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
import Control.Applicative
import Control.Monad.Trans.State.Strict
import Control.Monad.Trans.Class
import Control.Monad.Morph
import Data.Monoid
newtype MonoidState m a = MonoidState { st :: StateT [Int] m a }
deriving (Functor, Applicative, Monad, MonadTrans, MFunctor)
@tranma
tranma / With.hs
Last active August 29, 2015 14:07
Using MMonad and MonadTransControl to define (with :: (a -> Foo m x) -> Foo m x) in terms of (with :: (a -> m x) -> Foo m x)
{-# LANGUAGE GeneralizedNewtypeDeriving, TypeFamilies, TupleSections #-}
import Control.Exception
import Control.Applicative
import Control.Monad.State.Strict
import Control.Monad.Trans.Class
import Control.Monad.Trans.Either
import Control.Monad.Error
import Control.Monad.Trans.Control
import Control.Monad.Morph
@tranma
tranma / Plot.hs
Created October 20, 2015 09:34
Plot simple y(x) functions in ASCII
-- * Plot simple y(x) functions in ASCII
--
import Control.Monad
import Control.Arrow
import Control.Monad.ST
import Data.Array.ST
import Data.Array.Unboxed
import qualified Data.Array.ST as AS
import qualified Data.Array.MArray as AM
import Data.Ord
@tranma
tranma / Generic.hs
Created February 29, 2016 11:48
optparse-generic attempt
{-# LANGUAGE DeriveGeneric, ScopedTypeVariables, RankNTypes, InstanceSigs, DefaultSignatures, FlexibleContexts, TypeOperators, FlexibleInstances #-}
import Control.Applicative
import GHC.Generics
import Options.Applicative hiding (argument)
import Data.Monoid
newtype ExampleArg = ExampleArg Int
deriving Generic