-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhigherOrderPractical.hs
More file actions
36 lines (28 loc) · 921 Bytes
/
higherOrderPractical.hs
File metadata and controls
36 lines (28 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
module Morgan's where
thrice :: (a -> a) -> a -> a
thrice function x = function (function (function x))
thrice' :: (a -> a) -> a -> a
thrice' function = function . function . function
trimSp :: String -> String
trimSp = reverse . dropWhile isSpace . reverse . dropWhile isSpace
where
isSpace :: Char -> Bool
isSpace char =
if char == ' '
then True
else False
diffs list = zipWith (-) list (tail list)
locations :: Eq a => a -> [a] -> [Int] --Eq a says that first a must be able to be equated
locations item list =
map fst (filter isItem (zip [0..] list))
where
isItem (int, element) =
if element == item
then True
else False
splitter :: (a -> Bool) -> [a] -> ([a],[a])
splitter boolFunction list =
(takeWhile boolFunction list, dropWhile boolFunction list)
myLength xs = foldr function 0 xs
where
function x r = 1 + r