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 qualified Data.Map as M | |
import Data.List (nub, sort) | |
import qualified Data.Set as S | |
import Control.Applicative | |
-- problem 19 code | |
counts :: Ord a => [a] -> M.Map a Int | |
counts = foldl incr M.empty | |
where incr m x = M.insertWith (+) x 1 m |
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 Main where | |
import Pipes | |
import qualified Pipes.Prelude as P | |
import Pipes.Network.TCP | |
import qualified Data.ByteString as B | |
main :: IO () | |
main = | |
-- "serve" is from Network.Simple.TCP |
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 Keyboard | |
import List | |
import Window | |
import Color | |
import Random | |
input = dropRepeats Keyboard.space | |
ticks = fps 30 |
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
(declare-datatypes () ( | |
(Ty (base (idx Int)) | |
(arrow (src Ty) (tar Ty)) | |
(prod (c1 Ty) (c2 Ty)) | |
))) | |
(declare-datatypes () ( | |
(Expr exprA | |
exprAtoBtoC | |
exprB |
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
diag = go [] where | |
go active (xs:xss) = map head active ++ go (xs:map tail active) xss |
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
-- The list where nth element is the list of strings of length n. | |
strings = iterate (map (:) letters <*>) letterStrings | |
where letterStrings = map (:[]) letters | |
letters = ['a'..'z'] |
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
guard(pred, f) = if pred then f! | |
g(x) -> | |
y = getY! | |
<~ guard (x != y) | |
x + y |
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 qualified Data.Map as M | |
import Control.Arrow ((>>>)) | |
import Data.List (intercalate) | |
import GHC.Exts (sortWith) | |
main = interact $ words | |
>>> foldr incr M.empty | |
>>> M.toList | |
>>> sortWith (negate . snd) | |
>>> map show |
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 DeriveGeneric #-} | |
{-# LANGUAGE NamedFieldPuns #-} | |
{-# LANGUAGE RecordWildCards #-} | |
import System.Directory (getDirectoryContents) | |
import qualified System.IO.Strict as S | |
import Data.String.Utils (split, join) | |
import qualified Data.HashMap.Lazy as M | |
import qualified Data.HashSet as H | |
import qualified Data.ByteString.Lazy as B |
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 Prelude hiding (scanl, length, takeWhile, sum, map) | |
import Data.List.Stream | |
import System.Random.Mersenne.Pure64 | |
import qualified Data.Set as S | |
import Data.Word | |
randUpTo :: Int -> PureMT -> [Int] | |
randUpTo n gen = unfoldr make gen | |
where make g = let (k, g') = randomInt g in Just (k `mod` n, g') |
OlderNewer