8.5. Using Happy with GHCi
Prev | Chapter 8. Tips | Next

## 8.5. Using Happy with GHCi

GHCi's compilation manager doesn't understand Happy grammars, but with some creative use of macros and makefiles we can give the impression that GHCi is invoking Happy automatically:

- Create a simple makefile, called `Makefile_happysrcs`:

      HAPPY = happy
      HAPPY_OPTS =

      all: MyParser.hs

      %.hs: %.y
      	$(HAPPY) $(HAPPY_OPTS) $< -o $@

- Create a macro in GHCi to replace the `:reload` command, like so (type this all on one line):

      :def myreload (\_ -> System.system "make -f Makefile_happysrcs"
         >>= \rr -> case rr of { System.ExitSuccess -> return ":reload" ;
                                 _ -> return "" })

- Use `:myreload` (`:my` will do) instead of `:reload` (`:r`).

Prev | Up | Next
8.4. Conflict Tips | Home | 8.6. Basic monadic Happy use with Alex