<commit_before># Hazel

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](http://hazel.org/).

## Building and Running Hazel

### Build Status

- Development branch (`dev`) : [![Build Status](https://travis-ci.org/hazelgrove/hazel.svg?branch=dev)](https://travis-ci.org/hazelgrove/hazel)
- Stable branch (`master`): [![Build Status](https://travis-ci.org/hazelgrove/hazel.svg?branch=master)](https://travis-ci.org/hazelgrove/hazel)

### Prerequisites

Hazel is implemented in Reason/OCaml, and is compiled to Javascript for
the web browser via the `js_of_ocaml` compiler. An easy way to install
both OCaml and the necessary libraries is to install
[opam](https://opam.ocaml.org/). After having installed `opam` using
the instructions on their website, follow these steps:

- Make sure you have OCaml 4.08.1 (some older versions such as
  4.07.1 may also work, but 4.09 does not yet work):

  ```sh
  > ocaml --version
  The OCaml toplevel, version 4.08.1
  ```

  If you do not have OCaml 4.08.1, you can install it with the
  following:

  ```sh
  > opam switch create 4.08.1
  ```

- Make sure `opam` is updated:

  ```sh
  > opam update
  ```

- Run the Makefile in the `hazel` root folder to install the
  necessary OCaml dependencies:

  ```sh
  > make deps
  ```

### Compiling

We can now build the application.

```sh
> make release
```

The `make release` command does three things:

1. Generates some parsers using `menhir`.
2. Compiles the Reason code to OCaml bytecode using the OCaml compiler.
3. Compiles the OCaml bytecode to JavaScript
   (`_build/default/src/hazelweb/www/hazel.js`) using `js_of_ocaml`.

If something weird is going on, it sometimes helps to do a `make
clean`.

### Running

Once Hazel is compiled, you can see it in action with `make chrome`,
`make chromium`, or `make firefox` depending on which browser you
want to open it with.

Alternatively, you can manually open
`_build/default/src/hazelweb/www/index.html` in whatever your
preferred browser is.

### Debugging

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.

You can also run `dune utop src/hazelcore` to get a REPL in which you
can play with the core Hazel functions.<commit_msg>[docs] Update `README.md` and add instructions for installing `opam`<commit_after># Hazel

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](http://hazel.org/).

## Building and Running Hazel

### Build Status

- Development branch (`dev`):
  [![Build Status](https://travis-ci.org/hazelgrove/hazel.svg?branch=dev)](https://travis-ci.org/hazelgrove/hazel)

- Stable branch (`master`):
  [![Build Status](https://travis-ci.org/hazelgrove/hazel.svg?branch=master)](https://travis-ci.org/hazelgrove/hazel)

### Prerequisites

Hazel is implemented in Reason (a dialect of OCaml) and is compiled to
Javascript for the web browser via the `js_of_ocaml` compiler.  An easy way to
install both Reason and the necessary libraries is to use
[opam](https://opam.ocaml.org/) and the following steps.

- If you do not have `opam` installed, install it using the instructions in the
  [Installing `opam`](#installing-opam) section of this document.

- Update the list of available `opam` packages:

  ```sh
  opam update
  ```

- Install OCaml 4.08.1 (some older versions such as 4.07.1 may also work, but
  the necessary dependencies not work on 4.09 yet):

  ```sh
  opam switch create 4.08.1
  ```

- Run the Makefile in the `hazel` root folder to install the necessary OCaml
  dependencies:

  ```sh
  make deps
  ```

#### Installing `opam`

- If you are on Windows:

  - Go the to Microsoft Store, and search for and install "Ubuntu".  This will
    install the Windows Subsystem for Linux and the Ubuntu Linux distribution.

  - From the start menu or taskbar, open the "Ubuntu" application.  This will
    open a Bash/Linux shell.

- In the shell, run the following three commands:

  ```sh
  sudo add-apt-repository ppa:avsm/ppa
  ```

  ```sh
  sudo apt update
  ```

  ```sh
  sudo apt install m4 opam
  ```

- Check that the `opam` install worked by running:

  ```sh
  opam --version
  ```

  It should report at version 2.0 or greater.  If you have a version before
  that, the following instructions may not work.

- Initialize `opam`, by running:

  - If you are on windows:

    ```sh
    opam init --disable-sandboxing
    ```

  - On any other platform:

    ```sh
    opam init
    ```

- Enable `opam` for the current shell with the following:

  ```sh
  eval $(opam env)
  ```

### Compiling

You can now build the application with:

```sh
make release
```

The `make release` command does three things:

1. Generates some parsers using `menhir`.
2. Compiles the Reason code to OCaml bytecode using the OCaml compiler.
3. Compiles the OCaml bytecode to JavaScript
   (`_build/default/src/hazelweb/www/hazel.js`) using `js_of_ocaml`.

If something weird is going on, it sometimes helps to do a `make clean`.

### Running

Once Hazel is compiled, you can see it in action by opening
`_build/default/src/hazelweb/www/index.html` in your browser.

The command `make echo-html` echos that path to the terminal, so that you don't
have to remember it.

Thus you can launch Hazel with `BROWSER $(make echo-html)` where (depending on
your installed operating system and browser) `BROWSER` is one of:

- `firefox`,
- `chrome`,
- `chrome-browser`,
- `chromium`, or
- `chromium-browser`.

For Window's users, the path to the browser may not be so easy to type, so the
commands `make win-firefox` and `make win-chrome` will launch Hazel in the
browser.

### Debugging

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.

You can also run `make repl` to get a REPL in which you can play with the core
Hazel functions.
  
{'fraction_non_alphanumeric': 0.09554993302574788, 'fraction_numerical': 0.006995088554844471, 'mean_word_length': 3.8068669527896994, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 10, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1103676', 'n_tokens_mistral': 2176, 'n_tokens_neox': 2068, 'n_words': 902}