Bank Queuing and Monitoring System
Group Members
Name
Email Address
i.
Ammar Qahtani
[email protected]
ii.
Faris almur
[email protected]
iii.
Ahmed Alalawi
[email protected]
Bank Queuing and Monitoring System
Introduction
-7.14 import Prelude hiding(drop,splitAt) drop : Int -> [a] -> [a] splitAt : Int -> [a] -> ([a],[a]) drop 0 x = x drop n [] = [] drop n (x:xs) = drop (n-1) xs splitAt 0 x = ([],x) splitAt n [] = ([],[]) splitAt n xs = (take n xs, drop n xs)
-7.11 import List ins : Int -> [Int] -> [Int] ins x [] = [x] ins x (y:ys) | x >= y = x:(y:ys) | otherwise = y:( ins x ys ) ins2 : Int -> [Int] -> [Int] ins2 x [] = [x] ins2 x (y:ys) | x < y = nub (x:(y:ys) | x = y = nub (y:ys) | otherwise = nub (y : ins2
-7.7 unique : [Int] -> [Int] unique [] = [] unique (x:xs) | (notElem x xs) = (x: (unique xs) | otherwise = unique ( deleteAll x xs) -deleteAll x xs: returns list xs with all elements that equaled x deleted deleteAll : Eq a => a -> [a] -> [a] deleteAll x [
-7.5 import Prelude hiding(and,or) and, or : [Bool] -> Bool - and [] = True: x and y and z and True = x and y and z - allows simple recursion and [] = True and (x:xs) | x = False = False | otherwise = and xs -or or or [] = False: x or y or z or False = x
-6.18 maxThreeOccurs : Int -> Int -> Int -> (Int, Int) maxThreeOccurs x y z = (max,count) | where | max = max x (max y z) | count = 3 - length -solved much better in 5.1.hs!
-7.15 -The result would be []. import Prelude hiding(take) take 0 _ = [] take n (x:xs) | n>0 = x : take (n-1) xs take x y | x<0 = error "PreludeListe.take: negative argument" take _ [] = []
-7.17 qSort : [Int] -> [Int] qSort [] = [] qSort (x:xs) = qSort [ y | y<-xs, y > x ] + [x] + qSort [ y | y<-xs, y < x ] -remark: only the last comparison operator has to be changed.
-14.12 - address data type type type type House = Num Int | Name String Name = String Zip = Int City = String Country = String
showHouse : House -> String showHouse (Num n) = show n showHouse (Name s) = s data Address = Address Name House Zip City Country
-14.8 - make a new instance of class Eq for type Shape instance Eq Shape where (=) = eqShape - no need to derive (Eq) in Shape because it's explicitly defined data Shape = Circle Float | Rectangle Float Float | Triangle Float Float Float - eqShape is the
-14.3 data Temp = deriving data Season deriving Cold | Hot (Show) = Spring | Summer | Autumn | Winter (Eq)
weather : Season -> Temp - weather function for New Zealand: The same, because their winter is - hot as well - weather for Brazil (crossed by the Eq
-1.2 data Season = Spring | Summer | Autumn | Winter deriving (Eq,Show) data Month = January | February | March | April | May | June | July | August | September | October | November | December deriving (Eq,Ord) season : Month -> Season season month | mont
-14.1 data Temp = Cold | Hot deriving (Show) data Season = Spring | Summer | Autumn | Winter deriving (Eq) weather : Season -> Temp weather season | season = Summer = Hot | otherwise = Cold - Preferable: The pattern matching version. Only two thirds of th
-14.23 import List data NTree = NilT | Node Int NTree NTree
collapse : NTree -> [Int] collapse NilT = [] collapse (Node x left right) = [x] + collapse left + collapse right maxElem : NTree -> Int maxElem = last. sort. collapse minElem : NTree -> Int minEl
-14.22 data NTree = NilT | Node Int NTree NTree
isElem : Int -> NTree -> Bool isElem _ NilT = False isElem x (Node y left right) | x = y = True | otherwise = isElem x left | isElem x right