Instantly share code, notes, and snippets.

View Balance.hs
data Balance =
Balance !Int
!Int
deriving (Eq, Show)
instance Semigroup Balance where
Balance a b <> Balance c d
| b <= c = Balance (a + c - b) d
| otherwise = Balance a (d + b - c)
View ExpandMap.hs
module ExpandMap
( expandIntMap
) where
import Control.Monad.State (evalState, get, put)
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
import Data.Traversable (for)
-- >>> expandIntMap '0' 50 (IntMap.fromList (zip [0,5..50] ['a' .. 'z']))
View Main.hs
-- To run:
-- $ nix-shell -p "haskellPackages.ghcWithPackages (ghc: [ghc.reactive-banana])" --run "runhaskell ./Main.hs"
module Main where
import Control.Concurrent (threadDelay)
import Control.Event.Handler (newAddHandler)
import Control.Monad (replicateM_)
import Reactive.Banana.Combinators
( Event
View List.hs
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -Wall #-}
module List where
import Data.Bool (Bool)
import Data.Function (const)
import Data.Ord ((<=))
import GHC.Int (Int)
import GHC.Num ((-))
View BankersQueue.hs
module BankersQueue where
import Prelude hiding (head, tail)
data Queue a =
Queue [a] !Int [a] !Int
deriving (Show)
empty :: Queue a
empty = Queue [] 0 [] 0
View Main.hs
{-# LANGUAGE GADTs #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -Wall #-}
module Main where
import Data.Function ((&))
data Locked
View Constrained.hs
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Data.Constrained
( Constrained(unconstrained)
, constrain
) where
import Data.Bool ((&&), otherwise)
View Sized.hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE ExplicitNamespaces #-}
{-# LANGUAGE TypeOperators #-}
module Data.Text.Sized
( Text
View Main.hs
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))
View Main.hs
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)