Add example code

This commit is contained in:
Julian Ospald 2015-04-16 20:55:49 +02:00
부모 ea4f20e724
커밋 03943e4b7c
No known key found for this signature in database
GPG 키 ID: 220CD1C5BDEED020
1개의 변경된 파일41개의 추가작업 그리고 0개의 파일을 삭제

41
Code.hs Normal file
파일 보기

@ -0,0 +1,41 @@
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!"