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
fizzbuzz :: Int -> String | |
fizzbuzz n = unlines $ map fizzbuzz' [1 .. n] | |
where | |
fizzbuzz' n = let p = n `mod` 3 == 0 | |
q = n `mod` 5 == 0 | |
in case (p, q) of | |
(p, q) | p && q -> "FizzBuzz" | |
| p -> "Fizz" | |
| q -> "Buzz" | |
| otherwise -> show n |
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
vendor/ | |
composer.lock |
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 FuncList<'a> = 'a list -> 'a list | |
type CPSFuncList<'a> = FuncList<'a> -> FuncList<'a> | |
// Monoid comprehension | |
type CPSFuncListBuilder() = | |
member self.Combine (first : CPSFuncList<'a>, second : CPSFuncList<'a>) : CPSFuncList<'a> = | |
(fun k -> second (fun tail -> first (fun tail' -> k tail') tail)) | |
member self.Zero() : CPSFuncList<'a> = (fun k tail -> k tail) | |
member self.Yield (value : 'a) : CPSFuncList<'a> = (fun k tail -> k (value :: tail)) | |
member self.YieldFrom (value : CPSFuncList<'a>) : CPSFuncList<'a> = 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
// for more info http://www.cs.tufts.edu/~nr/cs257/archive/john-hughes/lists.pdf | |
type FuncList<'a> = 'a list -> 'a list | |
// Monoid comprehension | |
type FuncListBuilder() = | |
member self.Combine (first : FuncList<'a>, second : FuncList<'a>) : FuncList<'a> = (first << second) | |
member self.Zero() : FuncList<'a> = id | |
member self.Yield (value : 'a) : FuncList<'a> = fun tail -> value :: tail | |
member self.YieldFrom (value : FuncList<'a>) : FuncList<'a> = value | |
member self.Delay ( f : unit -> FuncList<'a>) : FuncList<'a> = (fun tail -> f () tail) |
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 #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
module RotateArgs where | |
data Z = Z | |
data S n = S n | |
class RotateArgs n a 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
modelIO :: IO a -> Model a | |
modelIO action = do | |
Model $ ReaderT (\_ -> action) | |
insertBook :: Book -> Model (LoadedCoreEntity Book) | |
insertBook bookSpec = do | |
bookGid <- (modelIO randomIO) :: Model UUID | |
bookRow <- head `fmap` query insertQuery [ toSql "Hello" ] | |
return $ bookFromRow bookRow | |
where insertQuery = unlines [ "INSERT INTO book (name)" |
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
bookResource :: Controller () | |
bookResource = do | |
gid <- ((fromString . unpack . fromJust) <$> getParam "gid") >>= (\gid' -> gid' `onNothing` "Invalid BBID") | |
maybeBook <- model $ getBook gid | |
case maybeBook of | |
Nothing -> generic404 "The request book could not be found" | |
Just book -> do | |
book <- model $ loadAuthorCredit book | |
book <- model $ set lBookAuthorCredit book <$> (loadForAuthorCredits $ bookAuthorCredit book) | |
editions <- model $ findBookEditions book |
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
-- This changes bookAuthorCredit from AuthorCreditReference to AuthorCredit | |
loadAuthorCredit :: Book -> Model Book | |
-- This changes all PersonReference's in an AuthorCredit to just Person | |
loadForAuthorCredits :: AuthorCredit -> Model AuthorCredit | |
-- This gets the AuthorCredit for a Book | |
bookAuthorCredit :: Book -> AuthorCredit | |
-- This 'sets' the AuthorCredit for a Book (returning a new Book) |
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
{ | |
process := make(chan *feat.Feature) | |
buffer := make(chan *feat.Feature, 1000) | |
wg := new(sync.WaitGroup) | |
if *cores < 2 { | |
*cores = 2 | |
} | |
for i := 0; i < *cores-1; i++ { | |
go func(){wg.Add(1); processServer(intervalTree, process, buffer); wg.Done()} | |
} |
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
data BTree a | |
= Null | |
| Leaf a | |
| Node a (BTree a) (BTree a) | |
deriving (Show) | |
-- makeTree :: [a] -> BTree a | |
-- makeTree xs = | |
instance Binary a => Binary (BTree a) where |