Skip to content

psel-org/psel

Repository files navigation

psel: Elisp(Emacs Lisp) backend for PureScript

WIP

Motivation

Elisp is powerful and flexible, but when it comes to complex logic code, some might prefer strongly typed language. Since it is possible to call PS functions from elisp, it is possible to write partially in PS. Also, you can reuse PureScript libraries as long as they do not depend on JS/browser specific libraries.

Installation

Currently, there is no release yet. To install psel command, you can build from source or use nix to install.

Build from source

Requires cabal-install and GHC 8.10.7.

git clone git@github.com:psel-org/psel.git
cd psel
cabal install

Install using Nix(flake.nix)

Requires nix >= 2.4.

nix profile install github:psel-org/psel

Usage

Psel is intended to use through Spago. Set backend = "psel" in your spago.dhall file. There is no package-set release yet. You can use WIP package-set https://raw.githubusercontent.com/psel-org/package-sets/main/src/el-0.14.5-20211116/packages.dhall for now.

{ name = "your-project-name"
, dependencies = [ "prelude" ]
, packages = https://raw.githubusercontent.com/psel-org/package-sets/main/src/el-0.14.5-20211116/packages.dhall
, backend = "psel"
, sources = [ "src/**/*.purs", "test/**/*.purs" ]
}

spago build will output all .el files under output.el directory. To require from emacs, add this path to load-path variable.

Module and Top-level bindings

Data.Foo module will be transpiled to Data.Foo.el. Top-level binding fooBar in Data.Foo module will be transpiled to (defvar Data.Foo.fooBar ...).

Type

Purescript Elisp
Int Integer
Double Double
String String
Array Vector
Char Integer(elisp doen't have char type)
Boolean True -> t, False -> nil (elisp doesn't have boolean type)
Records alist (e.g. (('foo . 1) ('bar . "a")))
Unit nil
Data types Vector with constructor tag symbol in first slot and arguments in the remaining slots. Constructor with no argument will be represented by tag symbol only.
e.g. Just 42 -> ['Just 42]
e.g. Nothing -> 'Nothing
Tuple Tuple a b -> (cons a b)
List Cons 1 (Cons 2 Nil)) -> (list 1 2)

Optimization

TCO(Tail-Call Optimization)

Currently, TCO is only applied to certain forms of self-recursion functions. TCO will convert these self-resursive calls to while s-exp expression.

MagicDo

Implemented only for Effect monad. ST monad remains unoptimized. Also whileE and forE combinator of Effect monad is also untouched.

Uncurried types

Not done yet.

Data.Function.Uncurried(funcitons package) and Effect.Uncurried(effects pacakge)

TODO

  • Support FFI
  • Prelude fork
  • Make an github orgiznation
  • Make psel command spago friendly
  • Create package-set
  • Implement TCO
  • Implement MagicDo
  • Support core libraries(WIP)
  • Minimal example and add Usage document
  • purescript-emacs
  • Support contrib libraries
  • Write some tests
  • Add flake.nix
  • Setup CI

References

Learned how to write a CoreFn-type PureScript backend from purenix and purerl.

About

Elisp(Emacs Lisp) backend for PureScript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published