An OCaml kernel for Jupyter notebook.
This provides an OCaml REPL with a great user interface such as markdown/HTML documentation, LaTeX formula by MathJax, and image embedding.
Requirements:
apt install zlib1g-dev
yum install -y zlib-devel
brew install zlib
apt install libffi-dev
yum install -y libffi-dev
brew install libffi
apt install libgmp-dev
yum install gmp-devel
brew install gmp
apt install libzmq5-dev
yum install zeromq-devel
(epel-release required)brew install zeromq
OCaml Jupyter can be installed by OPAM as follows:
$ pip install jupyter
$ opam install jupyter
$ opam install jupyter-archimedes # Jupyter-friendly 2D plotting library
$ ocaml-jupyter-opam-genspec
$ jupyter kernelspec install [ --user ] --name ocaml-jupyter "$(opam var share)/jupyter"
which will add the kernel to Jupyter. If the last command fails due to permission, --user
option or sudo
is required. You can use ocaml-jupyter
kernel by launching Jupyter notebook server:
$ jupyter notebook
If you get an error related to archimedes.cairo
during installation of jupyter-archimedes
,manually install cairo2
before archimedes
:
$ opam install "cairo2<0.6"
$ opam reinstall archimedes
$ opam install jupyter-archimedes
$ opam pin add jupyter https://github.com/akabe/ocaml-jupyter.git
cohttp.lwt
, and parse a response JSON by yojson
and ppx_deriving_yojson
.In addition, many examples (e.g, image processing, voice analysis, etc.) are available atdocker-ocaml-jupyter-datascience/notebooks.
These examples are placed in the public domain, e.g., you can edit, copy, and re-distribute with no copyright messages.
OCaml notebooks can be converted to HTML, Markdown, LaTeX, .ml
files, etc. using the jupyter nbconvert
command.For example, a .ipynb
file is converted into a .html
file as follows:
$ jupyter nbconvert --to html notebooks/introduction.ipynb
[NbConvertApp] Converting notebook notebooks/introduction.ipynb to html
[NbConvertApp] Writing 463004 bytes to notebooks/introduction.html
For exporting .ml
files, we recommend Jupyter-NBConvert-OCaml. It outputs .ml
files with Markdown cells as comments. After installation of Jupyter-NBConvert-OCaml, you can use --to ocaml
option to export a .ml
file:
$ jupyter nbconvert --to ocaml notebooks/introduction.ipynb
[NbConvertApp] Converting notebook notebooks/introduction.ipynb to ocaml
[NbConvertApp] Writing 2271 bytes to notebooks/introduction.ml
OCaml Jupyter kernel supports merlin-based code completion. Candidates are shown by Tab key like
The kernel uses .merlin file at a notebook directory for completion.
Inspection in Jupyter is also achieved by merlin. You can see documentation and type of an identifier by Shift+Tab key like
OCaml Jupyter includes some sub-packages:
jupyter
backend to Archimedes, and provides an empty interface.You can add kernels of different versions of OCaml as different names like:
$ opam switch create 4.06.0
$ ocaml-jupyter-opam-genspec
$ jupyter kernelspec install --name ocaml-jupyter-4.06.0 "$(opam var share)/jupyter"
$ opam switch create 4.07.1
$ ocaml-jupyter-opam-genspec
$ jupyter kernelspec install --name ocaml-jupyter-4.07.1 "$(opam var share)/jupyter"
OCaml 4.06.0
and OCaml 4.07.1
are displayed on Jupyter.If you want to prepare kernels for each opam-switch
environment,the following commands are useful:
$ ocaml-jupyter-opam-genspec
$ jupyter kernelspec install --name ocaml-jupyter-$(opam var switch) "$(opam var share)/jupyter"
ocaml-jupyter-opam-genspec
generates a configuration file like:
$ cat "$(opam var share)/jupyter/kernel.json"
{
"display_name": "OCaml 4.08.1",
"language": "OCaml",
"argv": [
"/bin/sh",
"-c",
"eval $(opam env --switch=4.08.1) && /home/xxxx/.opam/4.08.1/bin/ocaml-jupyter-kernel \"$@\"",
"-init", "/home/xxxx/.ocamlinit",
"--merlin", "/home/xxxx/.opam/4.08.1/bin/ocamlmerlin",
"--verbosity", "app",
"--connection-file", "{connection_file}"
]
}
See ocaml-jupyter-kernel --help
for details of command-line parameters in argv
. After you edit the file, re-register the kernel:
$ jupyter kernelspec install --name ocaml-jupyter "$(opam var share)/jupyter"
ocaml-jupyter-opam-genspec
depends on OPAM. If you use an other package manager, you need to write kernel.json
by hand or use provided suitable way for registering a new kernel (e.g., jupyter module on Nix).
A ready-to-use Docker image akabe/ocaml-jupyter-datascience is available on DockerHub.It contains OCaml Jupyter and many packages for data science.
$ docker run -it -p 8888:8888 akabe/ocaml-jupyter-datascience
[I 15:38:04.170 NotebookApp] Writing notebook server cookie secret to /home/opam/.local/share/jupyter/runtime/notebook_cookie_secret
[W 15:38:04.190 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 15:38:04.197 NotebookApp] Serving notebooks from local directory: /notebooks
[I 15:38:04.197 NotebookApp] 0 active kernels
[I 15:38:04.197 NotebookApp] The Jupyter Notebook is running at: http://[all ip addresses on your system]:8888/?token=4df0fee0719115f474c8dd9f9281abed28db140d25f933e9
[I 15:38:04.197 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 15:38:04.198 NotebookApp] No web browser found: could not locate runnable browser.
[C 15:38:04.198 NotebookApp]
Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
http://localhost:8888/?token=4df0fee0719115f474c8dd9f9281abed28db140d25f933e9
OCaml Jupyter can be run on Binder. Clickthe button to get started:
For more information, see this repository.
OCaml Jupyter can be run on Google Colab. In order to do this you first have to runthis Python notebookin your Colab instance. This will install the kernel and after that OCaml notebooks can be used on the same instance.
Many Jupyter kernels for functional programming languages are available such as IHaskell, Jupyter Scala, and Jupyter Rust. IOCaml is another practical OCaml kernel that inspires us, but it seems no longer maintained. OCaml Jupyter kernel differs from IOCaml in
OCaml Jupyter | IOCaml v0.4.8 | |
---|---|---|
Jupyter protocol | v5.2 | v3.2 |
OCaml PPX support | Yes | No |
Session key support | Yes | No |
Code completion | Yes | Yes |
Introspection | Yes | Yes |
User-defined messages | Yes | No |
Stdin | Yes | No |
Another OCaml kernel simple_jucaml seems too simple to use in practice.jupyter-kernel is a library to write OCaml kernels (not a kernel), but OCaml Jupyter kernel does not use this library.
Open an issue for any question, bug report, feature request. Your comments may help other users. Discussion in issues is better than contacting maintainers directly (e.g. by email).
We welcome your patch!
ln -sf $PWD/git/pre-commit $PWD/.git/hooks/pre-commit
opam install ocp-indent
for code format (in the git pre-commit hook)git push
the commits into your (forked) repository.master
of this repository from the branch you pushed.The environment variable OCAML_JUPYTER_LOG
controls the log level of OCaml Jupyter kernel.The following setting verbosely outputs log messages. They might help you debug.
$ export OCAML_JUPYTER_LOG='debug'
$ jupyter notebook
For Anaconda I suggest you a much easier and proper solution; just give a look at the nb_conda_kernels package. It allows you to “manage your conda environment-based kernels inside the Jupyter Noteboo
首先,ocaml的debug只能在unix系统上,以及windows的cwygin上(记不清了,我只在Ubuntu上用过) 一种方式是可以在toplevel中用trace,如: # let exchange i j v = let aux = v.(i) in v.(i) <- v.(j); v.(j) <- aux let one_pass_vect f
1.如果因为运行之后,文件特别大 直接把下面这段代码复制再cmd中 jupyter nbconvert C:\Users\dingwuhui\LSTM_四维.ipynb --to notebook --ClearOutputPreprocessor.enabled=True --output C:\Users\dingwuhui\LSTM_四维-1.ipynb
title: OCaml从入门到放弃 date: 2020-01-04 13:28:47 0. 前言 学习函数式语言 1. 注释与输入输出 OCaml注释如下: (* hello world *) 输入输出如下: 输入 read_int(): 读入一个整数 read_float(): 读入一个浮点数 read_line(): 读入一个字符串 输出 print_char 'a': 打印字符 pri
Ocaml学习笔记 Ocaml中标准的数据类型: 整型(type int):1,2,-2 字符型(type char):'a','\n','\x48' 字符串(type string):"ocaml" 布尔型(type bool):true,false 浮点型(type float):1.2,5.3 类型转换: 整型转换为字符串:string_of_int 1;; 整型转换为浮点型:float_o
运行 OCaml 代码 运行OCaml代码的最简单的方式是在你的浏览器中使用在线运行运行一个交互式会话。 关于在你的电脑上安装OCaml,请参考安装文档。 如果你想要尝试一些简单的OCaml表达式,你可以使用一个交互式顶层环境(interactive toplevel)或者REPL(Read–Eval–Print Loop)。ocaml命令提供了一个十分基础的顶层环境(你应该使用包管理器安装rlw
安装opam 参考官网安装步骤即可,比如对于centos系统,以root用户执行如下指令 cd /etc/yum.repos.d/ wget http://download.opensuse.org/repositories/home:ocaml/CentOS_7/home:ocaml.repo yum install opam 然后安装ocaml,使用系统包管理器安装 yum install o
安装ocaml 安装opam bash -c "sh <(curl -fsSL https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh)" 安装沙盒 yum install epel-release yum install bubblewrap yum install ocaml-camlp4-devel yum i
Overview Jane Street采用OCaml OCaml OCaml is a general purpose industrial-strength programming language with an emphasis on expressiveness and safety. It is the technology of choice in comapanies where
转换整数到浮点:float_of_int n 转换浮点到整数:int_of_float n 函数的定义 在Ocaml中,同其它强类型语言一样,函数取得一个预定义类型的参数并返回一个给定类型的值。函数的参数间简单的使用空格分开。 假如我们想定义下面的这些函数,它们的数学形式为: double : x -> 2X square : x -> x*x cube : x -> x^3 我们该如何在Ocam
OCaml MySQL Protocol 是 OCaml 实现的 MySQL 数据库协议,用于访问 MySQL 数据库。
IPython 是 Python 的原生交互式 shell 的增强版,可以完成许多不同寻常的任务,比如帮助实现并行化计算;主要使用它提供的交互性帮助,比如代码着色、改进了的命令行回调、制表符完成、宏功能以及改进了的交互式帮助。
问题内容: 知道OCAML / CAML IDE吗?特别是在Linux上运行的软件? 问题答案: Emacs处于Caml模式或Tuareg模式或TypeRex模式。TypeRex在emacs中为Taureg添加了自动补全功能- 对于喜欢更多图形化IDE的人来说,这是一个非常不错的功能。
本文向大家介绍OCaml 泛型算法,包括了OCaml 泛型算法的使用技巧和注意事项,需要的朋友参考一下 示例 高阶函数可用于实现通用算法,而无需向用户提供最终细节。例如,List.sort期望有一个比较功能,该功能允许实现各种排序方式。在这里,我们实现了不区分大小写的字符串排序: 在标准库中,尤其是在“列表”模块中,有一个丰富的高阶函数列表,例如参见List.fold_left和List.sort
本文向大家介绍OCaml匿名函数,包括了OCaml匿名函数的使用技巧和注意事项,需要的朋友参考一下 例子 由于函数是普通值,因此有一种方便的语法来创建不带名称的函数: 这很方便,因为否则我们必须首先命名该函数(请参阅let)才能使用它:
本站为对 OCaml 感兴趣者提供一套实用而详尽的教程。OCaml是一种快速、简洁、而强大的应用程序开发语言,我想大家也许已经知道这一点了,而且已经安装了 OCaml。