• Stars
    star
    659
  • Rank 65,906 (Top 2 %)
  • Language
    OCaml
  • License
    MIT License
  • Created over 7 years ago
  • Updated 9 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Hazel, a live functional programming environment with typed holes

Hazel Build Status

Hazel Mascot

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!

Building and Running Hazel

Short version

If you already have ocaml version 5.0.0 and least version 2.0 of opam installed, you can build Hazel by running the following commands.

To view Hazel, you have to serve it, on localhost for development (you can't run it from a file:/// URL due to browser restrictions on web workers.)

If you have python3 on your path, you can use the Python server via make serve, then navigate to http://0.0.0.0:8000/ in your browser.

Otherwise, run make echo-html-dir for the directory that needs to be served using the server of your choice.

Long Version

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.

Contributing

From OCaml to ReasonML

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.

Suggested Extensions for VS Code

Most of our team uses VisualStudio Code to write code. If you use VS Code, here are a few extensions that might be helpful.

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 typing breadcrumbs, and select View: Toggle Breadcrumbs from the dropdown menu to toggle breadcrumbs on and off.
  • Press Ctrl+Shift+. to start breadcrumbs navigation.

Suggested Setup for NeoVim

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>

Build System Details

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:

  1. Generate some internal parsers using menhir.
  2. Compile the Reason code to OCaml bytecode using the OCaml compiler.
  3. Compile the OCaml bytecode to JavaScript (_build/default/src/hazelweb/www/hazel.js) using js_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 also run make watch-release to continuously build the release build (takes longer per build).

Clean Build

To obtain an clean build, you may need to:

  • Clone the repository (if you have not), and enter the project root of your cloned Hazel project.

    git clone [email protected]:hazelgrove/hazel.git
    cd hazel
  • Setup a local OCaml environment specific to the project, and compile. If you have setup a local OCaml environment (there is a directory called _opam), you may want to first remove it.

    # opam switch remove ./
    opam switch create ./ 5.0.0
    eval $(opam env)
    make deps
    make

This sets up a standalone OCaml environment in the cloned project, independent of the one you sent in your home directory. This allow you to alternate dependencies, or test dependencies changes, without affect existing OCaml projects.

Debugging

Printing

You can print to the browser console using the standard print_endline function. This is probably the easiest method right now.

Source Maps

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.

Debug Mode

If Hazel is hanging on load or when you perform certain actions, you can load into Debug Mode by appending #debug to the URL and reloading. From there, you have some buttons that will change settings or reset local storage. Refresh without the #debug flag and hopefully you can resolve the situation from there.

Testing

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.

Continuous Integration

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.

More Repositories

1

tylr

a tiny tile-based editor
Reason
259
star
2

HZ

Simple reference implementation of Hazelnut using js_of_ocaml and OCaml React. (frozen -- ongoing development in the hazel repo)
OCaml
29
star
3

hazelnut-dynamics-agda

mechanization paired with https://github.com/hazelgrove/hazelnut-dynamics
Agda
19
star
4

agda-popl17

Mechanization of Hazelnut, as submitted to POPL 2017
Agda
16
star
5

diy-hazelnut

A template for you to implement Hazelnut yourself
Reason
15
star
6

livelits-tyde

Submission: "Livelits: Filling Typed Holes with Live GUIs (Extended Abstract)" to TyDe 2019 (ICFP workshop)
TeX
6
star
7

hazelnut-livelits-agda

mechanization for livelits paper, https://github.com/hazelgrove/livelits-paper
Agda
5
star
8

hazelnut-dynamics-paper

Paper exploring the dynamic semantics of Hazelnut
TeX
5
star
9

environment

Jupyter Notebook
4
star
10

error-localization-agda

Mechanization of the marked lambda calculus, a judgmental framework for total bidirectional type error localization and recovery.
Agda
4
star
11

agda-tfp16

Formalization of joint work submitted to TFP2016 (deprecated, see agda-popl17)
Agda
3
star
12

impl-tfp16

Holes and Zippers (deprecated, see HZ)
OCaml
3
star
13

artifact-popl17

POPL17 paper artifact
3
star
14

livelits-paper

Filling Typed Holes with Live GUIs
JavaScript
3
star
15

GRV

OCaml
3
star
16

grain

Reason
2
star
17

hazelnut-popl17

Submission to POPL 2017
TeX
2
star
18

editor-tfp16

submission to TFP 2016 (draft, see hazelnut-popl17 for latest)
TeX
2
star
19

editor-tyde19

TeX
2
star
20

hazelnut-icfp17

possible submission to icfp17, extending hazelnut with dynamics
TeX
1
star
21

tylr-build

HTML
1
star
22

phi

Proposals for Hazel Improvements (PHIs)
1
star
23

hazel-vision-tr

Vision paper accepted to SNAPL 2017.
TeX
1
star
24

action-macros-paper

Paper about composing edit actions in a macro-like way to define higher-level edit actions in Hazel
TeX
1
star
25

hazelgrove.github.io

Website for hazelgrove project
HTML
1
star
26

total-typing

Formalization of the Hazel 3 type system, loosely as-implemented
TeX
1
star
27

build

JavaScript
1
star
28

hazelnat-myth-agda

The mechanization of our ongoing work on type+example synthesis with big-step hazelnut dynamics
Agda
1
star