Need a tutorial for using GHC to parse and typecheck Haskell

I'm working on a project for analyzing Haskell code. I decided to use GHC to parse the source and infer types rather than write my own code to do that. Right now, I'm slogging through the Haddock docs, but it's slow going. Does anyone know of a good tutorial? EDIT: To clarify, I'm not looking for something like hlint. I'm writing my own tool to analyze the runtime charac

需要一个使用GHC解析和类型检查Haskell的教程

我正在开发一个分析Haskell代码的项目。 我决定使用GHC来解析源代码并推断类型,而不是编写自己的代码来实现。 现在,我正在抨击Haddock文档,但是它的进展缓慢。 有谁知道一个很好的教程? 编辑:澄清,我不寻找像hlint的东西。 我正在编写我自己的工具来分析Haskell代码的运行时特性,所以就像我在写一个不同的hlint。 我正在寻找的基本上是维基页面GHC作为一个库的扩展。 亚当,这是非常艰难的雪橇。 自2006年推出

How to compile Haskell into the untyped lambda calculus (or GHC core)?

I'm looking for ways how to convert a simple Haskell program (no imported libraries, just data types and pure functions) into a term of the untyped lambda calculus. A promising approach seems to be to use GHC API to compile a program into GHC core, which can be then converted into the untyped lambda calculus. How to use GHC API to load a Haskell program and compile it into Core? From the

如何将Haskell编译为无类型lambda演算(或GHC核心)?

我正在寻找如何将简单的Haskell程序(没有导入的库,只是数据类型和纯函数)转换为无类型lambda演算的术语。 一个有希望的方法似乎是使用GHC API将程序编译成GHC核心,然后可以将其转换为无类型的lambda演算。 如何使用GHC API加载Haskell程序并将其编译到Core? 从ghc文档中的GHC模块文档: compileToCoreModule :: GhcMonad m => FilePath -> m CoreModule 这是访问与模块相对应的Core绑定的方式。 compileToC

How to get only the object file without main function by ghc?

[Source Code] data FooBar = Foo | Bar [Command] $ ghc -c foo_bar.hs foo_bar.hs:1:0: The function 'main' is not defined in module 'Main' [Configuration] Glasgow Haskell Compiler, Version 6.12.3, for Haskell 98, stage 2 booted by GHC version 6.10.4 You should define your type in a module, and then compile it: module Test where data FooBar = Foo | Bar By invoking ghc

如何仅通过ghc获取没有main函数的目标文件?

[源代码] 数据FooBar = Foo | 酒吧 [命令] $ ghc -c foo_bar.hs foo_bar.hs:1:0:'main'功能未在模块'Main'中定义 [组态] Glasgow Haskell编译器版本6.12.3,用于Haskell 98,第2阶段由GHC版本6.10.4启动 你应该在模块中定义你的类型,然后编译它: module Test where data FooBar = Foo | Bar 通过调用ghc -c foo_bar.hs ,将生成目标文件foo_bar.o而不必定义main 。

Evaluation of Haskell Statements/Expressions using GHC API

For a tool I'm writing ( http://hackage.haskell.org/package/explore ) I need a way to read haskell function definitions at run-time, apply them to values from my tool and retrieve the results of their application. Can anyone give me a very basic example using GHC (6.10.4 or 6.12.1) API? example function definition to be read from a file at run-time: f x = 10**(4/1102*x - 1) expected pro

使用GHC API评估Haskell语句/表达式

对于我正在编写的工具(http://hackage.haskell.org/package/explore),我需要一种在运行时读取haskell函数定义的方法,将它们应用于我的工具中的值并检索其应用程序的结果。 任何人都可以给我一个使用GHC(6.10.4或6.12.1)API的非常基本的例子吗? 在运行时从文件中读取的示例函数定义: f x = 10**(4/1102*x - 1) 预期的节目输出 --mapM_ print $ map f [428, 410, 389] 3.577165388142748 3.077536885227335 2.582130

Profiling a partially evaluated program

For the purposes of profiling a partially evaluated program, I'm interested in knowing the best way to terminate a GHC program. This is useful for profiling programs that take a long time to run, possibly as long as forever. With GHC 7.4.2, I was able to profile a non-terminating program by enabling profiling (-prof -auto-all) and running my program with +RTS -p . This generated increment

分析部分评估的程序

为了描述部分评估的程序,我有兴趣了解终止GHC程序的最佳方法。 对于需要花费很长时间才能运行的程序进行性能分析非常有用,可能只要永久性运行。 使用GHC 7.4.2,我可以通过启用分析(-prof -auto-all)和使用+RTS -p运行我的程序来分析非终止程序。 这生成了增量分析数据。 该程序可能会被^c杀死,并且.prof文件将包含数据。 在GHC 7.6和更高版本中,看起来如果程序可以用一个^ c结束,那么分析信息被写入输出。 但是(

Real World Haskell, Chapter 5, SimpleJSON compile error

According to another question, parts of Real World Haskell are now obsolete. I'm only on Chapter 5, but I'm having problems compiling a simple example to an executable binary. Two modules are given: module SimpleJSON ( JValue(..) , getString , getInt , getDouble , getBool , getObject , getArray , isNull ) where data JValue = JString String

真实世界Haskell,第5章,SimpleJSON编译错误

根据另一个问题,真实世界Haskell的部分现在已经过时了。 我只是在第5章,但是我在编译一个可执行二进制文件的简单示例时遇到问题。 给出两个模块: module SimpleJSON ( JValue(..) , getString , getInt , getDouble , getBool , getObject , getArray , isNull ) where data JValue = JString String | JNumber Double | JBool Bool |

Why doesn't sleep work?

Why does c_sleep return immediately in the following code? {-# LANGUAGE ForeignFunctionInterface #-} import Foreign.C.Types import Data.Time.Clock import Control.Concurrent foreign import ccall unsafe "unistd.h sleep" c_sleep :: CUInt -> IO CUInt main :: IO () main = do getCurrentTime >>= print . utctDayTime c_sleep 10 >>= print -- this doesn't sl

为什么不睡觉工作?

为什么c_sleep在下面的代码中立即返回? {-# LANGUAGE ForeignFunctionInterface #-} import Foreign.C.Types import Data.Time.Clock import Control.Concurrent foreign import ccall unsafe "unistd.h sleep" c_sleep :: CUInt -> IO CUInt main :: IO () main = do getCurrentTime >>= print . utctDayTime c_sleep 10 >>= print -- this doesn't sleep getCurrentTim

GHC version check in code

I'm contributing to Alex, and it obviously depends on a lot of libraries and should compile for a lot of versions. I need to use a function that is only available from GHC 7.6.1 to handle an error better. So I want to use an #if ... to import said function, else, I'll deal with the error differently. I've seen some: #if __GLASGOW_HASKELL__ >= 610 import Control.Exception ( br

GHC版本检入代码

我为Alex做出了贡献,显然它依赖于很多库,并且应该为许多版本编译。 我需要使用GHC 7.6.1中提供的函数来更好地处理错误。 所以我想用#if ...来导入这个函数,否则,我会以不同的方式处理这个错误。 我见过一些: #if __GLASGOW_HASKELL__ >= 610 import Control.Exception ( bracketOnError ) #endif 所以我做了: #if __GLASGOW_HASKELL__ >= 761 import Text.Read ( readMaybe ) #endif 认为761是GHC 7.6.1版

EclipseFP is searching for GHC and cannot find it

I have working Eclipse (Kepler Service Release 2) + EclipseFP (2.6.0) + Haskell Platform under Windows 8.1 x64. In one moment after some cabal install, EclipseFP stopped working and showing me: The program ghc version >=6.4 is required but it could not be found. I have: Uninstalled Haskell Platform Deleted C:UsersmyuserAppDataRoamingcabal* Deleted C:Program Files (x86)Haskell* Ins

EclipseFP正在寻找GHC并找不到它

我在Windows 8.1 x64下运行Eclipse(Kepler Service Release 2)+ EclipseFP(2.6.0)+ Haskell Platform。 在安装一些cabal之后的一会儿,EclipseFP停止工作并向我展示: 该程序ghc版本> = 6.4是必需的,但无法找到。 我有: 卸载Haskell平台 已删除C: Users myuser AppData Roaming cabal * 已删除的C: Program Files文件(x86) Haskell * 安装Haskell平台2013.2 用我的Haskell工作区运行Eclipse

Why i can't compile with GHC if code contain module definition?

I'am trying to compile a very small haskell code with ghc: module Comma where import System.IO main = do contents <- getContents putStr (comma contents) comma input = let allLines = lines input addcomma [x] = x addcomma (x:xs) = x ++ "," ++ (addcomma xs) result = addcomma allLines in result The command i'm using to compile is : ghc --m

如果代码包含模块定义,为什么我不能用GHC编译?

我试图用ghc编译一个非常小的haskell代码: module Comma where import System.IO main = do contents <- getContents putStr (comma contents) comma input = let allLines = lines input addcomma [x] = x addcomma (x:xs) = x ++ "," ++ (addcomma xs) result = addcomma allLines in result 我用来编译的命令是: ghc - 制作Comma.hs 我得到这个答案: [1 of 1]