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
| data LockerState = Taken | Free deriving (Show, Eq) | |
| type Code = String | |
| type LockerMap = Map.Map Int (LockerState, Code) | |
| lockerLookup :: Int -> LockerMap -> Either String Code | |
| lockerLookup lockerNumber map = case Map.lookup lockerNumber map of | |
| Nothing -> Left $ "Locker " ++ show lockerNumber ++ " doesn't exist!" | |
| Just (state, code) -> if state /= Taken | |
| then Right code | |
| else Left $ "Locker " ++ show lockerNumber ++ " is already taken!!" |
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 qualified Data.Map as Map | |
| data Person = Person { firstName :: String, | |
| lastName :: String, | |
| age :: Int | |
| } deriving (Eq, Show, Read) | |
| data Day = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday deriving (Eq, Ord, Show, Read, Bounded, Enum) | |
| type AssocList k v = [(k, v)] |
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
| -- data Person = Person String String Int Float String String deriving (Show) | |
| data Person = Person { firstName :: String, | |
| lastName :: String, | |
| age :: Int, | |
| height :: Float, | |
| phoneNumber :: String, | |
| flavor :: String | |
| } deriving (Show) |
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
| module Shapes | |
| ( Point, Shape, area, nudge, baseCircle, baseRect ) where | |
| -- 値コンストラクタが1つしかない場合、データ型と値コンストラクタは同じ名前にする(慣例) | |
| data Point = Point Float Float deriving (Show) | |
| data Shape = Circle Point Float | Rectangle Point Point deriving (Show) | |
| area :: Shape -> Float | |
| area (Circle _ r) = pi * r ^ 2 | |
| area (Rectangle (Point x1 y1) (Point x2 y2)) = (abs $ x2 - x1) * (abs $ y2 - y1) |
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
| data Shape = Circle Float Float Float | Rectangle Float Float Float Float | |
| deriving (Show) | |
| area :: Shape -> Float | |
| area (Circle _ _ r) = pi * r ^ 2 | |
| area (Rectangle x1 y1 x2 y2) = (abs $ x2 - x1) * (abs $ y2 - y1) |
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 qualified Geometry.Sphere as Sphere | |
| import qualified Geometry.Cuboid as Cuboid | |
| import qualified Geometry.Cube as Cube | |
| printSphere :: Float -> String | |
| printSphere value = show $ Sphere.volume value | |
| printCuboid :: Float -> Float -> Float -> String | |
| printCuboid a b c = show $ Cuboid.volume a b c |
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
| module Geometry | |
| ( sphereVolume, | |
| sphereArea, | |
| cubeVolume, | |
| cubeArea, | |
| cuboidArea, | |
| cuboidVolume | |
| ) where | |
| -- exportしている関数 |
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 qualified Data.Map as Map | |
| import Data.Char | |
| phoneBook = | |
| [("betty", "555-2938"), | |
| ("betty", "342-2492"), | |
| ("bonnie", "452-2928"), | |
| ("pasty", "493-2928"), | |
| ("pasty", "943-2928"), | |
| ("pasty", "827-9162"), |
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 | |
| import Data.Char | |
| wordNums :: String -> [(String, Int)] | |
| wordNums = map (\ws -> (head ws, length ws)) . group . sort . words | |
| isIn :: (Eq a) => [a] -> [a] -> Bool | |
| needle `isIn` haystack = any (needle `isPrefixOf`) (tails haystack) | |
| encode :: Int -> String -> String |
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 | |
| import qualified Data.Map as M | |
| numUniques :: (Eq a) => [a] -> Int | |
| numUniques = length . nub | |
| wordNums :: String -> [(String,Int)] | |
| wordNums = map (\ws -> (head ws, length ws)) . group . sort . words |