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 (intercalate) | |
import Data.List.Split (splitOn) | |
nub_spaces :: String -> String | |
nub_spaces = splitOn " " |> filter (/= "") |> join " " | |
(|>) = flip (.) | |
join = intercalate | |
main = do |
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 Text.Parsec | |
type Parser = Parsec String () | |
data T = T { hours :: Int, minutes :: Int, seconds :: Int } | |
instance Show T where | |
show (T h m s) = show h ++ " hours " ++ show m ++ " minutes " ++ show s ++ " seconds" | |
parse' :: Parser a -> String -> Either ParseError a |
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
type Action | |
= FetchDocuments | |
| ErrorOccurred String | |
| DocumentsFetched (List Document) | |
model : Model | |
model = | |
{ documents = Right [] | |
, queryString = "" | |
} |
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
type alias Person = | |
{ name : String | |
} | |
type alias Model = | |
{ persons : List Person | |
} | |
model : Model | |
model = |
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
#!/usr/bin/env runhaskell | |
{-# LANGUAGE DeriveAnyClass #-} | |
{-# LANGUAGE DeriveGeneric #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
import qualified Data.Aeson as Aeson | |
import Data.Text | |
import Data.Time.Clock | |
import GHC.Generics |
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 Text.Printf | |
import Data.List | |
data P = P (Double, Double) deriving (Ord, Show, Eq) | |
class Geom a where | |
sub :: a -> a -> a | |
crossProduct :: a -> a -> Double | |
distance :: a -> a -> Double |
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.Lens | |
λ: :t _1 | |
_1 :: (Functor f, Field1 s t a b) => (a -> f b) -> s -> f t | |
λ: :t _2 | |
_2 :: (Functor f, Field2 s t a b) => (a -> f b) -> s -> f t | |
λ: :i Getting | |
type Getting r s a = (a -> Const r a) -> s -> Const r s | |
-- Defined in ‘Control.Lens.Getter’ | |
λ: view _2 (1,2) | |
2 |
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.Monad | |
romanValues = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1] | |
romanDigits = words "m cm d cd c xc l xl x ix v iv i" | |
theRomans = zip romanValues romanDigits | |
toRoman' :: Int -> String | |
toRoman' n = fst $ foldl romFold ("", n) theRomans | |
romFold :: ([a], Int) -> (Int, [a]) -> ([a], Int) |
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.Parallel | |
import Data.Monoid | |
data Collection = Collection | |
{ s :: Integer | |
, average :: Double | |
, count :: Integer | |
} | |
deriving (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
-- regex implementation | |
module Main where | |
import Control.Exception | |
import Prelude hiding (max,min) | |
data Atom = Literal Char | |
| OneOf String | |
| NoneOf String |