Difference between revisions of "GHC/As a library (up to 6.8)"

From HaskellWiki
< GHC
Jump to: navigation, search
 
Line 1: Line 1:
  +
= Using GHC as a library =
  +
 
In GHC 6.5 and subsequently you can import GHC as a Haskell library, which lets you write a Haskell program that has access to all of GHC.
 
In GHC 6.5 and subsequently you can import GHC as a Haskell library, which lets you write a Haskell program that has access to all of GHC.
   
Line 7: Line 9:
 
and so on.
 
and so on.
   
= Getting started =
+
== Getting started ==
 
You'll need to get a version of GHC that supports the GHC API. Either download ghc from [http://www.haskell.org/ghc/docs/latest/html/building/sec-cvs.html CVS] or use darcs: <tt>darcs get --partial http://darcs.haskell.org/ghc</tt>. There are also [http://www.haskell.org/ghc/dist/current/dist nightly snapshot distributions] available.
 
You'll need to get a version of GHC that supports the GHC API. Either download ghc from [http://www.haskell.org/ghc/docs/latest/html/building/sec-cvs.html CVS] or use darcs: <tt>darcs get --partial http://darcs.haskell.org/ghc</tt>. There are also [http://www.haskell.org/ghc/dist/current/dist nightly snapshot distributions] available.
   

Revision as of 10:51, 20 January 2006

Using GHC as a library

In GHC 6.5 and subsequently you can import GHC as a Haskell library, which lets you write a Haskell program that has access to all of GHC.

This page is a place for everyone to add

  • Notes about how to get it working
  • Comments about the API
  • Suggestions for improvement

and so on.

Getting started

You'll need to get a version of GHC that supports the GHC API. Either download ghc from CVS or use darcs: darcs get --partial http://darcs.haskell.org/ghc. There are also nightly snapshot distributions available.

To use the GHC API you say simply

  import GHC

Doing this imports the module GHC from the package ghc, which comes with GHC 6.5 and subsequent. The module GHC exports the "GHC API", which is still in a state of flux. Currently it's not even Haddock-documented. You can see the source code (which is somewhat documented) here http://cvs.haskell.org/cgi-bin/cvsweb.cgi/fptools/ghc/compiler/main/GHC.hs

Here's an example main program that does it [attachment:Main.hs]