@hackage core-of-name0.1.0.0

Print the Core representation of a binding with a GHC plugin.

core-of-name

CI

GHC plugin that prints the Core intermediate representation of annotated Haskell bindings during compilation.

Based on the technique described in Finding the Core of an expression using Template Haskell and a custom GHC Core plugin, which in turn was inspired by inspection-testing

Usage

In the module whose bindings you want to inspect, enable TemplateHaskell and the plugin, then call coreOf or coreOfWith after the binding:

coreOf — print Core to stdout

{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fplugin=CoreOfName.Plugin #-}
module MyModule where

import CoreOfName.Types (coreOf)

f :: Double -> Double -> Double
f = \x y -> sqrt x + y

coreOf 'f

The Core representation of f will be printed interleaved with the normal compiler output during stack build / cabal build.

coreOfWith — write Core to a file

Use coreOfWith to direct the output to a file instead of stdout with this shorthand:

{-# LANGUAGE TemplateHaskell #-}
{-# language OverloadedStrings #-}
{-# OPTIONS_GHC -fplugin=CoreOfName.Plugin #-}
module MyModule where

import CoreOfName.Types (coreOfWith)

f :: Double -> Double -> Double
f = \x y -> sqrt x + y

coreOfWith "output.core" 'f

NB if two or more declarations use the same output file, the file will be overwritten. It is best to assign one Core output file per function.

The string literal is an Options value via the IsString instance and is equivalent to OToFile "output.core".

Explicit Options

You can also pass Options values directly:

import CoreOfName.Types (coreOfWith, Options(..))

-- print to stdout (same as coreOf)
coreOfWith OPrintCore 'f

-- write to a file
coreOfWith (OToFile "output.core") 'f

Building

stack clean && stack build