简体   繁体   English

在 Haskell 应用程序中创建 Haskell REPL

[英]Creating a Haskell REPL within a Haskell application

I'm trying to embed a Haskell REPL within one of my Haskell applications.我正在尝试在我的 Haskell 应用程序之一中嵌入 Haskell REPL。 The idea would be that only a subset of the Haskell libraries would be loaded by default, plus my own set of functions, and the user would use those in order to interact with the environment.这个想法是默认情况下只加载 Haskell 库的一个子集,外加我自己的一组函数,用户将使用这些函数与环境交互。

To solve this problem, I know one way would be to create a (mini-)Haskell parser + evaluator and map my mini-Haskell parser's functions to actual Haskell functions, but I'm sure there is a better way to do this.为了解决这个问题,我知道一种方法是创建一个(迷你)Haskell 解析器 + 评估器和 map 我的 mini-Haskell 解析器的函数到实际的 Haskell 函数,但我确信有更好的方法来做到这一点。

Is there a nice and clean way to build a REPL for Haskell using Haskell?有没有一种使用 Haskell 为 Haskell 构建 REPL 的好方法?

A few things that already exist:一些已经存在的东西:

  • GHCi, of course, both in the sense of being able to look at how it's implemented or being able to use it directly (ie, have your REPL just talk to GHCi via stdin/stdout). GHCi,当然,无论是从能够查看它的实现方式还是能够直接使用它的意义上来说(即,让您的 REPL 只通过 stdin/stdout 与 GHCi 对话)。
  • The full GHC API , which lets you hook into GHC and let it do all the heavy lifting for you--loading files, chasing dependencies, parsing, type checking, etc.完整的 GHC API ,它可以让您连接到 GHC 并让它为您完成所有繁重的工作——加载文件、跟踪依赖项、解析、类型检查等。
  • hint , which is a wrapper around a subset of the GHC API, with a focus on interactive interpretation rather than compilation--which seems to fit what you want to do. hint ,它是 GHC API 的一个子集的包装器,侧重于交互式解释而不是编译——这似乎适合您想要做的事情。
  • mueval , an evaluator with limits on loaded modules, resource use, etc, basically a "safe" interactive mode. mueval ,一个对加载的模块、资源使用等有限制的评估器,基本上是一种“安全”的交互模式。 It's what lambdabot uses, if you've ever been in the #haskell IRC channel.如果您曾经在#haskell IRC 频道中过,那就是 lambdabot 使用的东西。

All of the above are assuming that you don't want to deal with writing a Haskell interpreter yourself, which is probably the case.以上所有内容都假设您不想自己编写 Haskell 解释器,可能就是这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM