Yhc/API/Core

From HaskellWiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Part of Yhc

(Download)

Yhc Core is a way of dumping and using the internal representation of Yhc in an external project. The code related to this, including data types, is found in src/compiler/Core directory of the Yhc source code.

Blog Posts

The following sequence of blog posts probably gives a useful introduction to Yhc Core.

Generating Core

To generate Core, simply give the compiler the option -core or -corep. For example, when compiling

module FibMain where
main xs = pam daeh xs
daeh (x:xs) = x
pam f [] = []
pam f (x:xs) = f x : pam f xs

You get the output

$ yhc -core FibMain.hs
======  Human Readable Core:
FibMain.pam v220 v221 =
    case v221 of
        Prelude.[] -> (Prelude.[])
        Prelude.: v222 v223 ->
            (Prelude.: (YHC.Internal._apply1 v220 v222) (FibMain.pam v220 v223))
FibMain.daeh v224 =
    case v224 of
         Prelude.: v225 v226 -> v225
         _ -> (Prelude.error (LAMBDA228))
LAMBDA228 =
    (prim_STRING "FibMain: Pattern match failure in function at 7:1-7:15.")
FibMain.main v227 = (FibMain.pam FibMain.daeh v227)

The -core option gives human readable Core output, in a style very similar to Haskell. The -corep option gives a deriving Show output of the Core, which can be read back in with read very easily. The machine Core also contains source code locations for statements.

Compared to GHC Core

  • Types - Yhc has none, GHC has lots.
  • Familiarity - Yhc looks like Haskell, GHC is somewhat related, but not as close.
  • Name mangling - Yhc preserves names much better.
  • Source locations - Yhc keeps these, GHC doesn't.

Users

  • Catch - Case and Termination Checker for Haskell by Neil Mitchell. This takes Core as an input.
  • Dr Haskell - give hints to beginners about useful Haskell functions/idioms.