import qualified Data.Map as Map
solve :: Ord a => Map.Map a a -> [(a,a)] -> String
solve _ [] = "YES"
solve hash (x:xs)
| Map.member (fst x) hash = "NO"
| otherwise = solve (Map.insert (fst x) (snd x) hash) xs
solve1 = solve Map.empty
This gives the following error:
main.hs:13:10: error:
* Ambiguous type variable `a0' arising from a use of `solve'
prevents the constraint `(Ord a0)' from being solved.
Relevant bindings include
solve1 :: [(a0, a0)] -> String (bound at main.hs:13:1)
Probable fix: use a type annotation to specify what `a0' should be.
These potential instances exist:
instance (Ord a, Ord b) => Ord (Either a b)
-- Defined in `Data.Either'
instance (Ord k, Ord v) => Ord (Map.Map k v)
-- Defined in `Data.Map.Internal'
instance Ord Ordering -- Defined in `GHC.Classes'
...plus 24 others
...plus 44 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
* In the expression: solve Map.empty
In an equation for `solve1': solve1 = solve Map.empty
I read a bunch of answers related to this here on stack overflow but it still wasn't quite clear. All of them stated the problem and the explanation but didn't list the possible fixes/workarounds. Or maybe I am too of a newbie to infer the solution on my own.
Any help would be appreciated.