This file contains hidden or 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 #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
module Main where | |
import qualified Data.ByteString.Char8 as B | |
import qualified Data.Text as T | |
import Data.Maybe | |
import Snap | |
import Snap.Snaplet.Heist |
This file contains hidden or 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
-- file: ch03/GrahamScan.hs | |
import Data.List | |
import Data.Ord | |
type Point = (Double, Double) | |
data Direction = LeftTurn | |
| RightTurn | |
| Straight |
This file contains hidden or 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 | |
import Data.Maybe | |
maybeToMonad :: (MonadPlus m) => Maybe a -> m a | |
maybeToMonad Nothing = mzero | |
maybeToMonad (Just x) = return x | |
type Sheep = Int | |
father :: Sheep -> Maybe Sheep |
This file contains hidden or 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
-- file: ch15/Supply.hs | |
next = S $ do st <- get | |
case st of | |
[] -> return Nothing | |
(x:xs) -> do put xs | |
return (Just x) |
This file contains hidden or 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
getD n = getD' n 2 where | |
getD' n factor | n == factor = factor | |
| n `mod` factor == 0 = getD' (n `div` factor) factor | |
| otherwise = getD' n (succ factor) |
This file contains hidden or 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 | |
isUnique :: (Ord a) => [a] -> Bool | |
isUnique = all (null . drop 1) . group . sort | |
cols = [0..7] | |
solutions = [vec | vec <- permutations cols | |
, isUnique [vec!!i + i | i <- cols] | |
, isUnique [vec!!i - i | i <- cols]] |
This file contains hidden or 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 | |
isUnique :: (Ord a) => [a] -> Bool | |
isUnique = all (null . drop 1) . group . sort | |
cols = [0..7] | |
solutions = [vec | vec <- permutations cols | |
, isUnique [vec!!i + i | i <- cols] | |
, isUnique [vec!!i - i | i <- cols]] |
NewerOlder