Questions tagged [ghc-api]

39 questions
7
votes
1 answer

Using GHC API to compile a program with optimisation

I want to compile a Haskell module to GHC Core, with optimisations applied, and use the resulting core output. However, when I use compileToCoreSimplified it doesn't seem to run all the normal optimisations. Taking the program: {-# OPTIONS_GHC -O2…
Neil Mitchell
  • 9,090
  • 1
  • 27
  • 85
7
votes
1 answer

Haskell GHC Dynamic Compliation Only works on first compile

Following the GHC tutorial posted here and alterations to this code following the advice in a previous stack overflow question I asked, I have created a program which is able to compile and run a module in Test.hs with a function print to print a…
7
votes
1 answer

Finding cabal packages when using the GHC API

I'm trying to make a program that typechecks haskell files for me using the GHC API. I've gotten the type checking to work for local files, but I have a specific cabal package that I need to be have available as well (the same package this…
Adam Bergmark
  • 7,316
  • 3
  • 20
  • 23
5
votes
1 answer

Dynamic loading of Haskell abstract syntax expression

Can we use GHC API or something else to load not text source modules, but AST expressions, similar to haskell-src-exts Exp type? This way we could save time for code generation and parsing.
modular
  • 1,099
  • 9
  • 22
5
votes
0 answers

How do I write code to modify the AST of a Haskell source file without losing the pragmas?

I need to make some changes to an existing Haskell source file, and write out the modified source code. I'd like to use the GHC API for this, so that the result is consistent with current Haskell. My current approach, which is here, is something…
Chris Smith
  • 2,615
  • 19
  • 18
5
votes
2 answers

Importing a known function from an already-compiled binary, using GHC's API or Hint

I have a module Target, with a function Target.accessMe inside it. I compile this module in some way, then get rid of the source code. Now, what series of arcane incantations must I do to make a different program dynamically import Target.accessMe?…
user12163
5
votes
1 answer

Why directly imported functions in GHC differ so much with functions I write with the source code copied from GHC Libraries

module Has (r,p,s) where import Prelude ((==),Bool(..),otherwise,(||),Eq) import qualified Data.List as L filter :: (a -> Bool) -> [a] -> [a] filter _pred [] = [] filter pred (x:xs) | pred x = x : filter pred xs | otherwise =…
TorosFanny
  • 1,702
  • 1
  • 16
  • 25
4
votes
0 answers

GHC API: finding implementations of instance functions

I'm writing a symbolic execution engine for Haskell using GHC, and often I need to find the instance implementations of various functions in the program. However, after leafing through many ASTs produced by the typechecker, I can't see any way to…
concat
  • 3,107
  • 16
  • 30
4
votes
0 answers

Implementation tips for whole-program static analysis for Haskell

As part of a research project on property-based testing, I need to do static whole-program analysis of Haskell programs. I'm looking for suggestions on how to implement whole-program analysis of Haskell programs, hopefully without building lots of…
Brad Larsen
  • 995
  • 1
  • 12
  • 20
4
votes
1 answer

GHC-api and typechecking class constraints

I am trying to build a simple ghci-like console using ghc-api. I've gotten to a point where I can extract Type's of expressions using exprType and to evaluate them. Is there also an easy way to check if the type of the expression has an instance of…
aleator
  • 4,436
  • 20
  • 31
3
votes
0 answers

Does GHC API dynamic loading work only with modules from installed packages?

I try to follow the way described in the answer to this question. I have ExampleModule.o and ExampleModule.hi files in the working directory and I try to load ExampleModule.f function. But I get error message (with verbosity level set to 3): Failed…
modular
  • 1,099
  • 9
  • 22
3
votes
1 answer

How do I force interpretation in Hint

How do I force interpretation mode in Hint (Language.Haskell.Interpreter)? I have this code: module Main where import Language.Haskell.Interpreter import Control.Monad main = do res <- runInterpreter (test "test") case res of Left e ->…
Daniel O
  • 4,607
  • 6
  • 44
  • 52
3
votes
2 answers

Global variables via unsafePerformIO in Haskell

The GHC API requires that some initialisation occurs before invocation. Specifically, parseStaticFlags can only be called once. I have functions that can call runGhc :: MaybeFilePath :: Ghc a -> IO a multiple times to run some GHC API methods. …
vivian
  • 1,434
  • 1
  • 10
  • 13
3
votes
1 answer

Using the GHC API to do a "dry run" of code compilation

I'm working on a fairly simple text-editor for Haskell, and I'd like to be able to highlight static errors in code when the user hits "check." Is there a way to use the GHC-API to do a "dry-run" of compiling a haskell file without actually compiling…
jmite
  • 8,171
  • 6
  • 40
  • 81
3
votes
1 answer

Treating a String as a Haskell Program

As a small part of a larger University project, I need to write what is essentially an extremely crude IDE. The idea is to to take input from a gtk text box, treat that string as if it is in a .hs file, and evaluate a function within it. My main…
Craig Innes
  • 1,573
  • 11
  • 23