-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhaskellFun7.hs
More file actions
40 lines (25 loc) · 894 Bytes
/
haskellFun7.hs
File metadata and controls
40 lines (25 loc) · 894 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
37
38
39
40
import Data.Char
locate :: Eq a => a -> [a] -> [Int]
locate x ys = map fst (filter (\(a,b) -> b == x) (zip [1..] ys))
histogram :: [Int] -> String
histogram xs = concat (map f xs)
where
f :: Int -> String
f n = replicate n '*' ++ "\n"
manyFuns :: [a -> b] -> a -> [b]
manyFuns fs v = map (\f -> f v) fs
mySort :: Ord a => (a -> a -> Bool) -> [a] -> [a]
mySort p [] = []
mySort p (x:xs) = ins x (mySort p xs)
where
ins y [] = [y]
ins y (z:zs)
| p y z = y:z:zs
| otherwise = z: (ins y zs)
isFixPt :: Eq a => (a -> a) -> a -> Bool
isFixPt f val = val == (f val)
changeFirst :: (a -> Bool) -> a -> [a] -> [a]
changeFirst p val [] = []
changeFirst p val (x:xs)
| (p x) = val : xs
| otherwise = x : changeFirst p val xs