I am writing a function in Haskell to make a histogram from any element ListLikewith Ord:
import qualified Data.ListLike as LL
...
frequencies :: (Ord x, LL.ListLike xs x) => xs -> [(x, Int)]
frequencies xs = LL.map (\x->(LL.head x, LL.length x)) $ LL.group $ LL.sort xs
When I try to compile the above code, I get an error of ambiguous types:
Ambiguous type variable `full0' in the constraint:
(LL.ListLike full0 xs) arising from a use of `LL.group'
Probable fix: add a type signature that fixes these type variable(s)
In the expression: LL.group
In the second argument of `($)', namely `LL.group $ LL.sort xs'
In the expression:
LL.map (\ x -> (LL.head x, LL.length x)) $ LL.group $ LL.sort xs
LL.grouphas a type (ListLike full0 full, ListLike full item, Eq item) => full -> full0that matches (Eq a) => [a]->[[a]]speaking in terms of regular lists.
I do not understand why there is a problem with ambiguous types. Is Haskell somehow unable to conclude that there is a type such as "ListLike with fullas elements", i.e. full0?
source
share