Skip to content

Instantly share code, notes, and snippets.

@bradparker
bradparker / weekdays-until.hs
Last active January 25, 2018 07:23
Weekdays Until
module Main where
import Data.Time
import Data.Time.Clock
import Data.Time.Format
import Data.Time.Calendar
import Data.Maybe
import System.Environment
import Text.ParserCombinators.ReadP
import Data.Char
@bradparker
bradparker / Scott.hs
Last active April 25, 2019 07:36
Wow
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RebindableSyntax #-}
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -Wall #-}
module Scott where
import qualified Prelude as Builtin
import qualified Data.Char as Builtin
import GHC.Num (Num(fromInteger, (-), (+)))
module Main
( main
) where
import Control.Arrow ((&&&))
import Control.Monad.Trans.State (StateT(StateT), evalStateT)
import Data.List (uncons, unfoldr)
import Data.Maybe (fromMaybe, listToMaybe)
import System.Environment (getArgs)
@bradparker
bradparker / recursive-foldable.hs
Last active May 10, 2018 05:05
Recurisive foldable... more or less
{-# LANGUAGE DeriveFoldable #-}
module Main where
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Foldable
data Object a
= Value a
@bradparker
bradparker / Lens.hs
Last active August 23, 2018 05:23
Lenses
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE RankNTypes #-}
module Main where
import Control.Applicative (Applicative(..))
import Data.Bool (Bool(False, True), not)
import Data.Char (toUpper)
import Data.Function (($), (&), (.), const, flip)
@bradparker
bradparker / .gitignore
Last active September 12, 2018 08:25
StateT Parser
dist
@bradparker
bradparker / Main.hs
Last active February 8, 2019 05:36
Parser
module Main where
import Data.Functor (void)
import Control.Applicative ((<|>), empty, many, some, optional)
import Control.Monad (msum, replicateM)
import Control.Monad.State (StateT(runStateT))
import Control.Monad.State.Class (get, put)
import Data.Char (isHexDigit, chr, isDigit, isSpace)
import Data.Map (Map)
import Data.Maybe (listToMaybe, fromMaybe)
@bradparker
bradparker / Main.hs
Last active November 21, 2018 22:10
Essence of the iterator pattern word count
module Main where
import Data.Bool (bool)
import Control.Monad ((<=<))
import Control.Monad.State (State, evalState, get, put)
import Data.Char (isSpace)
import Data.Foldable (traverse_)
import Data.Functor.Compose (Compose(Compose, getCompose))
import Data.Functor.Const (Const(Const, getConst))
import Data.Functor.Product (Product(Pair))
@bradparker
bradparker / Sized.hs
Created October 15, 2018 12:14
Playing around with length indexed text
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE ExplicitNamespaces #-}
{-# LANGUAGE TypeOperators #-}
module Data.Text.Sized
( Text
@bradparker
bradparker / Constrained.hs
Last active October 16, 2018 09:22
Constrained
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Data.Constrained
( Constrained(unconstrained)
, constrain
) where
import Data.Bool ((&&), otherwise)