Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Haskell counting elements of a list
- report :: [[String]] -> String -> [String]
- report (x:xs) typ = do
- case typ of
- "registrations" -> reportReg (map head xs)
- "completions" -> reportReg (map head xs)
- reportReg :: [String]
- reportReg [x] = do
- print x
- print 1
- reportReg (x:xs) = do
- let count = instances x (x:xs)
- print x
- print count
- let newlist = filter (==x) (x:xs)
- reportReg newlist
- instances::String->[String]->Int
- instances x [] = 0
- instances x (y:ys)
- | x==y = 1+(instances x ys)
- | otherwise = instances x ys
- reportReg :: [String]
- reportReg :: [String] -> IO ()
- Prelude> :load typef.hs
- [1 of 1] Compiling Main ( typef.hs, interpreted )
- Ok, modules loaded: Main.
- *Main> :t report
- report :: (Eq a, Show a) => [[a]] -> [Char] -> IO ()
- *Main> :t reportReg
- reportReg :: (Eq a, Show a) => [a] -> IO ()
- *Main> :t instances
- instances :: (Num t, Eq a) => a -> [a] -> t
- reportReg :: [String]
- reportReg :: [String] -> ???
- reportReg :: [String] -> IO ()
- reportReg :: [a] -> IO ()
- reportReg [] = do return ()
- reportReg xs = do print (head x)
- print (count x xs)
- reportReg (tail xs)
- count :: a -> [a] -> Integer
- count x xs = length (filter (==x) xs)
Add Comment
Please, Sign In to add comment