Browse Source

Add example code

stripped-german
Julian Ospald 5 years ago
parent
commit
03943e4b7c
No known key found for this signature in database GPG Key ID: 220CD1C5BDEED020
1 changed files with 41 additions and 0 deletions
  1. +41
    -0
      Code.hs

+ 41
- 0
Code.hs View 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!"

Loading…
Cancel
Save