0

Many Haskell tutorials on Parsec alias function names for convenience. Alias is probably the wrong technical word here, but the idea is to use a simpler or alternative name for a function.

With ghci 8.0.1, the following gives an error:

import Text.ParserCombinators.Parser
run = parseTest

Here is the error:

error:
    • Ambiguous type variable ‘a0’ arising from a use of ‘parseTest’
      prevents the constraint ‘(Show a0)’ from being solved.
      Probable fix: use a type annotation to specify what ‘a0’ should be.
      These potential instances exist:
        instance Show Ordering -- Defined in ‘GHC.Show’
        instance Show Integer -- Defined in ‘GHC.Show’
        instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show’
        ...plus 22 others
        ...plus 17 instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • When instantiating ‘run’, initially inferred to have
      this overly-general type:
        forall s t a.
        (Text.Parsec.Prim.Stream s Data.Functor.Identity.Identity t,
         Show a) =>
        Text.Parsec.Prim.Parsec s () a -> s -> IO ()
      NB: This instantiation can be caused by the monomorphism restriction.
Failed, modules loaded: none.

What am I doing incorrectly, given that it is correct to say the following?

f :: Int -> Int
f x = x + 1

r = f
andro
  • 901
  • 9
  • 20

0 Answers0