1

Trying to compile Haskell.Happy example here: http://www.haskell.org/happy/doc/html/sec-using.html#sec-other-datatypes, after generating .hs file with happy, I'm getting the

No instance for (Show ([String, Int)] -> Int

error, trying to compile it, while first part of the example compiled and run fine

what am I doing wrong?

Edit: Full error message

No instance for (Show ([(String, Int)] -> Int))
  arising from a use of `print'
Possible fix:
  add an instance declaration for (Show ([(String, Int)] -> Int))
In the first argument of `(.)', namely `print'
In the second argument of `(>>=)', namely `print . calc . lexer'
In the expression: getContents >>= print . calc . lexer

I'm running

ghc example.hs

and the line is

main = getContents >>= print . calc . lexer

The possible duplicate question's answer is to pass an environment, but how could I do it here?

Sibi
  • 47,472
  • 16
  • 95
  • 163
Herokiller
  • 2,891
  • 5
  • 32
  • 50
  • I think the linked answer is right, but this implies an error in the Happy documentation. Load up your `example.hs` in `ghci` and ask it what type `calc` is (`:t calc`). I suspect you'll find it needs a `[(String, Int)]` parameter which isn't being satisfied. – Matthew Walton Jun 17 '14 at 13:56

1 Answers1

4

calc is probably of type [Token] -> [(String,Int)] -> Int, hence main should be:

main = getContents >>= print . ($ []) . calc . lexer

NOTE: The list in ($ []) is the environment

Ankur
  • 33,367
  • 2
  • 46
  • 72