[Haskell-beginners] Temporary values with polymorphic types

Amy de Buitléir amy at nualeargais.ie
Tue Feb 28 17:53:10 CET 2012

I'm trying to write a function that builds a temporary graph, performs some
operation on the graph, and then returns the result of the operation. The graph
isn't returned. Here's an example. (The real function is much more complicated.)

----- 8< -----
import Data.Graph.Inductive.Graph ( labNodes, mkGraph )

doSomething ∷ [a] -> [a]
doSomething xs = map snd $ labNodes $ mkGraph xs' []
  where xs' = zip [1..] xs
----- 8< -----

When I load this in GHCI, I get:

    Ambiguous type variable `gr0' in the constraint:
         gr0) arising from a use of `mkGraph'
    Probable fix: add a type signature that fixes these type variable(s)
    In the second argument of `($)', namely `mkGraph xs' []'
    In the second argument of `($)', namely `labNodes $ mkGraph xs' []'
    In the expression: map snd $ labNodes $ mkGraph xs' []
Failed, modules loaded: none.

More information about the Beginners mailing list