Skip to content

Instantly share code, notes, and snippets.

View moonmaster9000's full-sized avatar

moonmaster9000 moonmaster9000

View GitHub Profile
-- is there a GHC language extension that would
-- let me break up function definitions like this:
f1 some_pattern = expression1
f2 some_other_pattern = expression2
f1 yet_another_pattern = expression3
f2 another_pattern = expression4
--instead of having to group them together like this:
get ["echo", word]
| length word == 4 = body "4 letter word" >> status 403
| otherwise = body word
{-# LANGUAGE TypeFamilies, QuasiQuotes, TemplateHaskell #-}
import Yesod
data Echo = Echo
mkYesod "Echo" [$parseRoutes|
/echo/#String EchoR GET
|]
instance Yesod Echo where approot _ = ""
getEchoR s
| length s == 4 = permissionDenied "Forbidden: 4 letter word"
| otherwise = return $ RepPlain $ toContent s
import qualified Data.ByteString as B
main :: IO ()
main = do
td <- newTemplateDirectory' "templates" emptyTemplateState
quickServer $ templateHandler td defaultReloadHandler $ \ts ->
route [ ("echo/:s", echoHandler)
] <|>
templateServe ts <|>
dir "static" (fileServe ".")
infixl 9 ==>
f ==> g = g $ f
lee = Author "Gentry Lee"
clarke = Author "Arthur C. Clarke"
heinlein= Author "Robert Heinlein"
rama = Book "Garden of Rama"
catalog =
Catalog Map.empty Map.empty ==>
associate lee rama ==>
module Library
(Author,
Book,
AuthorIndex,
BookIndex,
Catalogued,
Catalog,
addAuthor,
addBook,
associate,
fac n = [1..] ==> take n ==> foldr (*) 1
infixl 9 ==>
f ==> g = g $ f
fac n = foldr (*) 1 $ take n $ [1..]
clarke = createAuthor "Arthur C. Clarke" ["Garden of Rama"]
lee = createAuthor "Gentry Lee" ["Garden of Rama"]
gardenAuthorsAccordingToClarke = map name $ authors $ head $ books clarke
-- ["Arthur C. Clarke"]
gardenAuthorsAccordingToLee = map name $ authors $ head $ books lee
-- ["Gentry Lee"]