The following example is my attempt at solving "take N most frequent words" in Haskell
.
I'd like to make heap
function to work for both String
and Text
.
It works for any of those, but not both as a
is a "rigid type variable".
Couldn't match type ‘a’ with ‘String’
‘a’ is a rigid type variable bound by
the type signature for heap :: H.Heap H.FstMaxPolicy (Occur, a)
What is the underlying problem?
{-# LANGUAGE OverloadedStrings, ExplicitForAll #-}
module Main where
import Data.MultiSet as M
import Data.String
import Data.Tuple as T
import Data.Text(Text)
import qualified Data.Text as T
import qualified Data.Heap as H
main = undefined
solution = H.take 3 heap
heap :: forall a. H.Heap H.FstMaxPolicy (Occur, a)
-- heap = foldr H.insert H.empty heapItems
heap = undefined
heapItems = fmap T.swap list
list = toOccurList frequencyDesc
frequencyDesc = foldr M.insert M.empty myWords
myWords :: forall a. (IsString a) => [a]
myWords = [ "a", "b", "a", "b", "c" ]