This file contains 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
__all__ = [ | |
"functional", | |
"later", | |
"X", "Y", "Z", "IF" | |
] | |
import functools | |
import operator |
This file contains 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 List | |
import Array | |
import System (getArgs) | |
discounts = listArray (1,5) ([1.0, 0.95, 0.9, 0.8, 0.75]::[Float]) | |
bookPrice = 8.0::Float | |
grouped :: Ord a => [a] -> [Int] | |
grouped = sort . (map length) . group . sort |
This file contains 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 | |
import Data.Maybe | |
import Control.Monad | |
import Control.Arrow | |
import System.Environment | |
newtype Account = Account { toList :: [Maybe Int] } deriving (Eq) | |
data Status = OK | Illegible | Error | Amb [Account] deriving (Eq) | |
instance Show Status where |
This file contains 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
match High = 1 `with` same value | |
match Pair = 2 `with` same value | |
match TwoPair = 2 `with` same value `plus` 2 `with` same value | |
match ThreeOfKind = 3 `with` same value | |
match Straight = 5 `with` sequential value | |
match Flush = 5 `with` same suit | |
match FullHouse = 3 `with` same value `plus` 2 `with` same value | |
match FourOfKind = 4 `with` same value | |
match StraightFlush = 5 `with` same suit `and` sequential value |
This file contains 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
module Regex (match) where | |
import Data.List | |
data Token = C Char | Start | End deriving (Eq) | |
match :: String -> String -> Bool | |
match re = not . null . filter (not.null) . fmap match' . tails . tokenize | |
where match' = flip (foldl' (>>=)) (compile re) . return | |
tokenize = (Start:) . (++[End]) . map C |
This file contains 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
module Roman where | |
import Data.Tuple | |
import Data.List | |
values = [ | |
(1000, 'M'), | |
(500, 'D'), | |
(100, 'C'), |
This file contains 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.Exception | |
import Control.Monad | |
import Control.Monad.IO.Class | |
import Data.ByteString.Lazy (ByteString) | |
import Data.ByteString.Lazy.UTF8 (toString) | |
import Data.Function | |
import Data.Enumerator | |
import Data.List | |
import Data.Maybe |
This file contains 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
-- See: http://swizec.com/blog/strangest-line-of-python-you-have-ever-seen/swizec/3012 | |
import Control.Monad | |
import Data.Maybe | |
import System.Environment | |
data NFA s i = NFA s [s] [((s,i),[s])] | |
runNFA (NFA i f t) = any (`elem` f) . foldM step i where | |
step s c = fromMaybe [] $ lookup (s,c) t |
This file contains 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 TypeFamilies, MultiParamTypeClasses, FlexibleInstances, EmptyDataDecls, OverlappingInstances, FlexibleContexts #-} | |
module Data.Algebra where | |
import Prelude hiding (Num(..), (/)) | |
import qualified Prelude as P | |
import Control.Applicative | |
import Control.Arrow (first, second) | |
import Data.Ratio (Ratio, (%)) |
This file contains 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, FlexibleInstances #-} | |
module CustomShow where | |
import Language.Haskell.TH | |
import Data.List (intercalate) | |
emptyShow :: Name -> Q [Dec] | |
emptyShow name = [d|instance Show $(conT name) where show _ = ""|] |
OlderNewer