Browse Source

Add example code

Julian Ospald 4 years ago
parent
commit
03943e4b7c
No account linked to committer's email address
1 changed files with 41 additions and 0 deletions
  1. 41
    0
      Code.hs

+ 41
- 0
Code.hs View File

@@ -0,0 +1,41 @@
1
+module Code where
2
+
3
+data WeekDay = Monday
4
+             | Tuesday
5
+             | Thursday
6
+             | Wednsday
7
+             | Friday
8
+             | Saturday
9
+             | Sunday
10
+  deriving (Show)
11
+
12
+
13
+f :: Int -> Int -> Int
14
+f x 0 = 1
15
+f x y = x * f x (y - 1)
16
+
17
+mod2 :: Int -> Int
18
+mod2 x
19
+  | x - 2 == 0 = 0
20
+  | x - 2 < 0  = x
21
+  | otherwise  = mod2 (x - 2)
22
+
23
+week :: [WeekDay]
24
+week = [Monday, Tuesday, Thursday, Wednsday
25
+       , Friday, Saturday, Sunday]
26
+
27
+isMonday :: WeekDay -> Bool
28
+isMonday Monday = True
29
+isMonday x      = False
30
+
31
+data Tree = Leaf Char
32
+          | Node Tree Int Tree
33
+  deriving Show
34
+
35
+data MaybeInt = NoError Int
36
+              | Error String
37
+
38
+calcSomething :: Int -> MaybeInt
39
+calcSomething x
40
+  | x < 100   = NoError (x * 5)
41
+  | otherwise = Error "Int out of range!"