Hazel is a live functional-programming environment rooted in the principles of type theory. You can find the relevant papers and more motivation at the Hazel website.
You can try Hazel online with either the trunk or dev version. Note that the trunk branch is updated infrequently and is currently almost two years behind!
If you already have ocaml
version 4.08.1 and least version 2.0 of opam
installed, you can build Hazel by running the following commands.
git clone [email protected]:hazelgrove/hazel.git
cd hazel
make deps
make dev
To run Hazel, run the command make echo-html
, which will print a filename.
Then use your preferred browser to open that file. For convenience, the
following make targets open the corresponding browser or invoke the
corresponding command immediately (see INSTALL.md):
make firefox
make chrome
make chrome-browser
make chromium
make chromium-browser
make win-chrome
make win-firefox
make xdg-open
make open
If you are unfamiliar with ocaml
or opam
, do not have them installed, or
just get stuck, we recommend you follow the step-by-step installation
instructions contained in INSTALL.md.
This link lets you type OCaml and see what the corresponding ReasonML syntax is: https://reasonml.github.io/en/try.
This is useful if you are trying to figure out the ReasonML syntax for something that you know the OCaml syntax for.
Most of our team uses VisualStudio Code to write code. If you use VS Code, here are a few extensions that might be helpful.
-
This extension provides full support for editing ReasonML source code and relevant tools:
-
Due to Reason's poor parse errors, unbalanced parentheses can be difficult to find. The following extensions help with that.
In addition to these extensions, enabling the breadcrumbs bar can make navigating a large code base easier. There are multiple ways to make the breadcrumbs bar visible:
- Click View / Show Breadcrumbs from the menu bar.
- Press
Ctrl+Shift+P
(macOS:Cmd+Shift+P
), start typingbreadcrumbs
, and selectView: Toggle Breadcrumbs
from the dropdown menu to toggle breadcrumbs on and off. - Press
Ctrl+Shift+.
to start breadcrumbs navigation.
If you enjoy your Vim binding and Vim setup, the following may help you set up your Reason IDE in NeoVim.
If you use vim, I recommend you to switch to NeoVim since it has a better support for multi-thread, and thus less likely to block you when you are programming.
To set up the LSP(Language Server Protocal), you need to set up your Language Client for Neovim and Language Server for ocaml.
After installing the previous two, you may want to copy the following to your neovim config file.
(assuming npm
have ocaml-language-server installed under /usr/bin
)
let g:LanguageClient_serverCommands = {
\ 'ocaml': ['/usr/bin/ocaml-language-server', '--stdio'],
\ 'reason': ['/usr/bin/ocaml-language-server', '--stdio']
\ }
" LanguageClient-neovim
nnoremap <F5> :call LanguageClient_contextMenu()<CR>
" Or map each action separately
nnoremap <silent> K :call LanguageClient#textDocument_hover()<CR>
nnoremap <silent> gd :call LanguageClient#textDocument_definition()<CR>
nnoremap <silent> gr :call LanguageClient#textDocument_references()<CR>
nnoremap <silent> gf :call LanguageClient#textDocument_formatting()<cr>
nnoremap <silent> <F2> :call LanguageClient#textDocument_rename()<CR>
Hazel is implemented in Reason (a dialect of OCaml) and is compiled to
Javascript for the web browser via the js_of_ocaml
compiler.
Though make
targets are provided as a convenience, they mostly translate to
dune
commands.
Invoking make
by itself is equivalent to invoking make dev
. With these
commands we pass additional flags to js_of_ocaml
that cause the insertion of
comments that map locations in the generated JS to locations in the source
files. This is useful for debugging purposes.
make dev
also auto-formats Reason source files using refmt
(this is what the
@src/fmt
alias is for). This ensures code from all contributors follows the
same style.
The make dev
and make release
commands do three things:
- Generate some internal parsers using
menhir
. - Compile the Reason code to OCaml bytecode using the OCaml compiler.
- Compile the OCaml bytecode to JavaScript
(
_build/default/src/hazelweb/www/hazel.js
) usingjs_of_ocaml
.
For a smoother dev experience, use make watch
to automatically watch
for file changes. This will require installing fswatch (see INSTALL.md).
You can print to the browser console using the standard print_endline
function. This is probably the easiest method right now.
js_of_ocaml
does support source maps and has some other flags that might be useful. If you experiment with those and get them to work, please update this README with some notes.
You can run all of the unit tests located in src/hazelcore/test
by running make test
.
Unit tests are written using ppx_expect and ppx_inline_tests. If you would like to adjust your expect tests to assert for the output that was last printed, run make fix-test-answers
.
If the inline test runner causes problems for you, you can likely resolve the issue by running opam update
then opam upgrade
.
When you push your branch to the main hazelgrove/hazel
repository, we
have a GitHub Action setup (see .github/workflows/deploy_branches.yml
)
that will build that branch (in release
mode) and deploy it to the URL
https://hazel.org/build/<branch name>
, assuming the build succeeds.
It usually takes about 2 minutes if the build environment cache hits, or 20+ minutes if not. You can view the status of the build in the Actions tab on Github.