2015-04-16 18:55:49 +00:00
|
|
|
module Code where
|
|
|
|
|
|
|
|
data WeekDay = Monday
|
|
|
|
| Tuesday
|
|
|
|
| Thursday
|
|
|
|
| Wednsday
|
|
|
|
| Friday
|
|
|
|
| Saturday
|
|
|
|
| Sunday
|
|
|
|
deriving (Show)
|
|
|
|
|
|
|
|
|
|
|
|
f :: Int -> Int -> Int
|
|
|
|
f x 0 = 1
|
|
|
|
f x y = x * f x (y - 1)
|
|
|
|
|
|
|
|
mod2 :: Int -> Int
|
|
|
|
mod2 x
|
|
|
|
| x - 2 == 0 = 0
|
|
|
|
| x - 2 < 0 = x
|
|
|
|
| otherwise = mod2 (x - 2)
|
|
|
|
|
|
|
|
week :: [WeekDay]
|
|
|
|
week = [Monday, Tuesday, Thursday, Wednsday
|
|
|
|
, Friday, Saturday, Sunday]
|
|
|
|
|
|
|
|
isMonday :: WeekDay -> Bool
|
|
|
|
isMonday Monday = True
|
|
|
|
isMonday x = False
|
|
|
|
|
|
|
|
data Tree = Leaf Char
|
|
|
|
| Node Tree Int Tree
|
|
|
|
deriving Show
|
|
|
|
|
|
|
|
data MaybeInt = NoError Int
|
|
|
|
| Error String
|
|
|
|
|
|
|
|
calcSomething :: Int -> MaybeInt
|
|
|
|
calcSomething x
|
|
|
|
| x < 100 = NoError (x * 5)
|
|
|
|
| otherwise = Error "Int out of range!"
|
2015-04-19 22:36:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
f' :: Int -> Int
|
|
|
|
f' x = let y p = x + p
|
|
|
|
in x + (y 2)
|
|
|
|
|
|
|
|
addTwo :: [Int] -> [Int]
|
|
|
|
addTwo [] = []
|
|
|
|
addTwo (x:xs) = (x + 2) : addTwo xs
|
|
|
|
|
|
|
|
f'' :: String -> Bool
|
|
|
|
f'' xs = even . length . (\x -> x ++ "Hello world") $ xs
|
2015-04-21 12:14:24 +00:00
|
|
|
|
|
|
|
g :: Int -> Bool
|
|
|
|
g x = case x - 2 of
|
|
|
|
2 -> True
|
|
|
|
5 -> True
|
|
|
|
x -> False
|