This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Map (Map) | |
import qualified Data.Map as M | |
import Data.Maybe | |
data Trie k v = Trie (Maybe v) (Map k (Trie k v)) deriving Show | |
empty :: Trie k v | |
empty = Trie Nothing M.empty | |
look :: Ord k => [k] -> Trie k v -> Maybe v |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Monoid | |
data FizzBuzz = N | I Int | S String | |
instance Monoid FizzBuzz where | |
mempty = N | |
N `mappend` N = N | |
N `mappend` I i = S $ show i | |
N `mappend` S x = S x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE BangPatterns, OverloadedStrings, FlexibleInstances, CPP #-} | |
module Main where | |
import Data.ByteString (ByteString) | |
import qualified Data.ByteString as S | |
import qualified Data.ByteString.Char8 as B | |
import qualified Data.ByteString.Lazy as L | |
import Blaze.ByteString.Builder (copyByteString, Builder, toLazyByteString) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- | |
Thundering herd on epoll with a non-blocking listening socket. | |
Compile: ghc -O ThunderingHerd.hs -threaded | |
Run this and do "telnet localhost 3000" to see new thundering herd. | |
-} | |
module Main where | |
import Control.Concurrent | |
import Control.Exception |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Criterion.Main | |
import qualified Data.ByteString.Char8 as BS | |
import Data.Time | |
import Data.Time.Clock.POSIX | |
import Data.UnixTime | |
import Network.HTTP.Date | |
-- import System.IO | |
import System.Locale | |
import System.Posix |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fib :: Int -> Integer | |
fib n = fib' n 0 1 | |
where | |
fib' 0 x _ = x | |
fib' m x y = fib' (m - 1) y (x + y) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE BangPatterns #-} | |
module Main where | |
import Control.Applicative | |
import Control.Monad | |
import Control.Monad.ST | |
import Criterion.Main | |
import Data.Array.ST | |
import Data.List (sort) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Tree a = Node a [Tree a] deriving Show | |
data Digit a = Zero | One (Tree a) deriving Show | |
data Schedule a = Schedule [[Digit a]] deriving Show | |
data Heap a = Heap [Digit a] (Schedule a) deriving Show | |
empty :: Heap a | |
empty = Heap [] (Schedule []) | |
isEmpty :: Heap a -> Bool | |
isEmpty (Heap [] _) = True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE BangPatterns #-} | |
module ScheduledMergeSort where | |
import Control.DeepSeq | |
newtype Schedule a = Schedule [[a]] deriving Show | |
data Segment a = Segment [a] (Schedule a) deriving Show | |
data MergeSort a = MergeSort Int [Segment a] deriving Show |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE BangPatterns #-} | |
module RealTimeQueue where | |
---------------------------------------------------------------- | |
import Control.Applicative ((<$>)) | |
import qualified GHC.Vacuum | |
import qualified GHC.Vacuum.ClosureType | |
import System.IO.Unsafe |