Use PureScript type checker as library

Hi all,

I’m experimenting with a monadic visual functional programming language in Haskell. Instead of writing my own type checker, I’d like to use PureScript’s type checker as a library. It has all features I need, especially row polymorphism. My idea is to do something like this:

  1. Preload some PureScript modules.
  2. Let an end user create or modify a program, represented internally using my own AST.
  3. Convert this internal AST to PureScript’s AST as my “main module”.
  4. Run PureScript’s type checker to get errors out, show them to the end user.
  5. Loop over (2) to (4).

Do you think this is feasible? I could use some pointers in the code which functions to use. I.e.

  • TypeChecker.typeCheckModule clearly type checks a module. But how to run monad m to get all errors and warnings?
  • How to keep the preloaded modules in memory and only recheck my generated AST? Could/Should I use the IDE functionality to preload and reload modules? The IDE interface suggests it only works with file names, not ASTs.
  • How to parse simple expressions like “sin pi * 4” into PureScript’s AST?

An alternative would be to generate PureScript source files and use the IDE as a library, or run purs in IDE mode, listening to JSON output. More ideas are welcome!

1 Like

Maybe my first post was a bit long and unclear, so let me try to restate my questions more directly:

  1. I’d like to parse a PureScript expression (so not an entire module or a declaration, only the part after the =), and get a PureScript AST out of it or an error: parseExpr :: String -> Either AST Error. What should I use?
  2. I’d like to feed a PureScript module to the PureScript type checker, and get succes or a list of failures out: checkModule : AST -> Either (List Error) Succes. What should I use?

Hope somebody can point me in the right direction!

Have you looked at the Try PureScript server code? It’s probably the simplest example of using the compiler as a library in the way you’re describing:


Didn’t think about looking at the Try PureScript code! Thanks for the tip Phil, this is very helpful :slight_smile: