-
Notifications
You must be signed in to change notification settings - Fork 0
/
Common.hs
39 lines (28 loc) · 934 Bytes
/
Common.hs
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
{- |
Module : <File name or $Header$ to be replaced automatically>
Description : An implementation of DPLL in Haskell.
Copyright : (c) Joshua T. Guerin, Ph.D.
License : <license>
Maintainer : [email protected]
Stability : experimental
Portability : portable
<module description starting at first column>
-}
module Common where
import Data.List (group, maximumBy, sort)
import Data.Ord (comparing)
--
mostFrequent literals =
head . maximumBy (comparing length) . group . sort $ literals
flatten :: [[a]] -> [a]
-- ^ Flattens a double list into a single list
flatten [] = []
flatten (x:xs) = flatten' x xs
flatten' :: [a] -> [[a]] -> [a]
-- ^ Does the work of flatten.
flatten' [] [] = []
flatten' [] (x:xs) = flatten' x xs
flatten' (x:xs) cnf = x:(flatten' xs cnf)
count :: Eq a => a -> [a] -> Int
-- ^ Count occurrences of value in provided parameter.
count value = length . filter (value ==)