idris-learning/chapter3/PatternMatching.idr
2021-07-09 10:00:22 +02:00

45 lines
1.1 KiB
Idris

module Main
surrond_with_braces : String -> String
surrond_with_braces x = "{" ++ x ++ "}"
allLengths : List String -> List Nat
allLengths strs = map length strs
invert : Bool -> Bool
invert True = False
invert False = True
describeList : Show a => List a -> String
describeList [] = "Empty"
describeList (x :: xs) = "Non-empty (" ++ show x ++ "), tail = " ++ show xs
showList : Show a => List a -> String
showList [] = "[]"
showList (x :: xs) = "[" ++ show x ++ showListInner xs
where
showListInner : Show a => List a -> String
showListInner [] = "]"
showListInner (x :: xs) = ", " ++ show x ++ showListInner xs
allLengthsNoMap : List String -> List Nat
allLengthsNoMap [] = []
allLengthsNoMap (word :: words) = length word :: allLengthsNoMap words
xor : Bool -> Bool -> Bool
xor False y = y
xor True y = not y
isEven2 : Nat -> Bool
isEven2 Z = True
isEven2 (S k) = not (isEven2 k)
mutual
isEven : Nat -> Bool
isEven Z = True
isEven (S k) = isOdd k
isOdd : Nat -> Bool
isOdd Z = False
isOdd (S k) = isEven k