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
-- http://blog.sigfpe.com/2006/12/evaluating-cellular-automata-is.html | |
data U x = U [x] x [x] | |
right (U a b (c:cs)) = U (b:a) c cs | |
left (U (a:as) b c) = U as a (b:c) | |
instance Functor U where | |
fmap f (U a b c) = U (map f a) (f b) (map f c) |
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.Char | |
strong = and . sequence conditions | |
where conditions = [ (>14) . length | |
, any isUpper | |
, any isLower | |
, any isDigit | |
] | |
{- |
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.Array | |
import Data.Maybe | |
data Piece = X | O | Empty deriving (Eq) | |
instance Show Piece where | |
show X = "X" | |
show O = "O" | |
show Empty = " " |
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.List | |
data Dir = N | S | E | W deriving (Eq, Show) | |
type Coord = (Int, Int) | |
(|+|) (x,y) (x',y') = (x+x',y+y') | |
infixl 6 |+| | |
toDelta d = case d of | |
N -> (0, -1) |
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 Control.Monad | |
import Control.Applicative | |
import Control.Proxy | |
import System.IO | |
import Prelude hiding (Left, Right) | |
data Input = Up | Down | Left | Right | Invalid deriving Show | |
toInput :: Char -> Input | |
toInput c = case c of |
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 RecordWildCards #-} | |
import Data.Monoid | |
data SalaryConfig = SalaryConfig | |
{ sAllowances :: Bool | |
, sBonus :: Bool | |
, sTax :: Bool | |
, sSurcharge :: Bool | |
} |
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.Ord (comparing) | |
import Data.Function (on) | |
import Data.List (groupBy) | |
type Point = (Int, Int) | |
points :: [Point] | |
points = [ (0, 1) | |
, (0, 2) | |
, (0, 2) |
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 Control.Monad | |
import Control.Applicative | |
import Control.Proxy | |
import qualified Control.Proxy.Trans.State as S | |
import System.IO | |
import Prelude hiding (Left, Right) | |
type Pos = (Int, Int) | |
data Input = Up | Down | Left | Right | Invalid 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 TemplateHaskell, OverloadedStrings, FlexibleInstances, TypeSynonymInstances #-} | |
import Network.URI (URI, parseURI) | |
import Network.HTTP | |
import Control.Applicative | |
import Data.Aeson | |
import qualified Data.ByteString.Lazy as BL | |
import Data.Maybe (fromJust) | |
redditURL = fromJust . parseURI $ "http://www.reddit.com/by_id/t3_1c578w.json" |
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
-- adapted from the pipes-network package | |
-- http://hackage.haskell.org/package/pipes-network | |
module TCP ( | |
-- * Server side | |
-- $server-side | |
serve, | |
serveFork, | |
-- ** Listening | |
listen, |