Does anyone have any experience with Haskell?
I've been trying to learn the language (based on the principle that if you can learn Haskell, you can learn anything), and I've been writing a number of small programs to help me learn.
One of the programs is a module that implements a bag data structure (similar to a set, but keeps track of the amounts of each item). I've been trying to construct a function to give me a sub-bag of the N most common elements, but I have yet to have much luck. Here's what I have so far:
module Bag where
import Data.Map as Map
type Bag a = Map a Int
fromList :: Ord a => [a] -> Bag a
fromList [] = Map.empty
fromList (x:xs) = Map.insertWith (+) x 1 (Bag.fromList xs)
mostCommon :: Int -> Bag a -> Bag a
{- How to implement this function ... -}