简体   繁体   中英

Creating a Haskell REPL within a Haskell application

I'm trying to embed a Haskell REPL within one of my Haskell applications. 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.

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.

Is there a nice and clean way to build a REPL for Haskell using Haskell?

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).
  • 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.
  • 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.
  • mueval , an evaluator with limits on loaded modules, resource use, etc, basically a "safe" interactive mode. It's what lambdabot uses, if you've ever been in the #haskell IRC channel.

All of the above are assuming that you don't want to deal with writing a Haskell interpreter yourself, which is probably the case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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