Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've broken this down into steps that should make this easier to grasp. First, sort the list, then reduce it into a list of (Word, Count) tuples.</p> <pre><code>import Data.Char (toLower) quicksort :: (Ord a) =&gt; [a] -&gt; [a] quicksort [] = [] quicksort (x:xs) = (quicksort [a|a&lt;-xs, a&lt;=x]) ++ [x] ++ (quicksort [a|a&lt;-xs, a&gt;x]) addCount :: String -&gt; [(String, Int)] -&gt; [(String, Int)] addCount a [] = [(a, 1)] addCount a (x:xs) | a == fst x = (fst x, (snd x) + 1) : xs | otherwise = x : (addCount a xs) occurrences :: [(String, Int)] -&gt; [String] -&gt; [(String, Int)] occurrences counts [] = counts occurrences counts (x:xs) = occurrences countL xs where countL = addCount x counts myList = ["AAA","America", "England", "Spain","Ireland", "aeroplane", "aeroplane", "Aeroplane", "AeRoPlAne", "helicopter", "HELICOPTER", "Zebra", "America", "Elephant", "abc", "A.B.C." , "haskell", "Haskell", "ZZZ", "zzz"] main = do let downcased = map (map toLower) myList let sorted = quicksort downcased let occurencesL = occurrences [] sorted putStrLn . show $ occurencesL putStrLn . show $ [head occurencesL, last occurencesL] </code></pre> <p>This is <em>very</em> verbose but, I'm hoping you have an easier time understanding what is happening this way.</p> <p>An example of a shorter way:</p> <pre><code> import Data.Char (toLower) import Data.List main = do let l = map (\a -&gt; (head a, length a)) $ groupBy (\x y -&gt; (map toLower x) == (map toLower y)) myList putStrLn . show $ l putStrLn . show $ [head l, last l] </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload