这里记录有关OCaml。(OCaml很对我胃口啊!)
- 漫谈函数式编程语言
- https://gitchat.csdn.net/activity/5c18c67a135357369db13686
- Real world OCaml V2(2021.Q4)
- 安装配置相关 http://dev.realworldocaml.org/install.html
spam switch create比较新的版本时,命令报错,说找不到这个版本。我电脑上OCaml之前安装的,已经比较老了,opam需要更新。
# 更新
opam update
spam upgrade
# 创建一个版本沙箱
opam switch create 4.13.1
eval $(opam env)
# 安装必要的库
opam install base utop
opam install core async yojson core_extended \
core_bench cohttp-async async_graphics \
cryptokit menhir
# 安装 OCaml Language Server
opam install ocaml-lsp-server
# 安装 ocamlformat
opam install ocamlformat
# 初始化ocaml
vim ~/.ocamlinit
# 输入下面代码(#不是注释,而是指令代码)
#use "topfind";;
#thread;;
#require "core.top";;
# 下载VSCode
# 安装插件 OCmal Platform
# File -> Add Folder to Workspace
# command + shift + p:
# 选择OCaml沙箱版本为上面create出来的4.13.1
opam install 时出现错误:
[ERROR] The compilation of conf-libX11 failed at "/Users/myname/.opam/opam-init/hooks/sandbox.sh build sh -exc
PKG_CONFIG_PATH=\"$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig:/opt/X11/share/pkgconfig\" pkg-config --libs x11".
#=== ERROR while compiling conf-libX11.1 ======================================#
# context 2.0.8 | macos/x86_64 | ocaml-base-compiler.4.13.1 | https://opam.ocaml.org#1c609c75
# path ~/.opam/4.13.1/.opam-switch/build/conf-libX11.1
# command ~/.opam/opam-init/hooks/sandbox.sh build sh -exc PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig:/opt/X11/share/pkgconfig" pkg-config --libs x11
# exit-code 1
# env-file ~/.opam/log/conf-libX11-72529-442377.env
# output-file ~/.opam/log/conf-libX11-72529-442377.out
### output ###
# + PKG_CONFIG_PATH=/Users/myname/.opam/4.13.1/lib/pkgconfig:/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig:/opt/X11/share/pkgconfig
# + pkg-config --libs x11
# Package x11 was not found in the pkg-config search path.
# Perhaps you should add the directory containing `x11.pc'
# to the PKG_CONFIG_PATH environment variable
# No package 'x11' found
x11的问题,运行下面命令
$ brew install libx11
由于之前mac系统升级过,导致如下错误:
$ brew install libx11
Updating Homebrew...
/usr/local/Homebrew/Library/Homebrew/os/mac/version.rb:33:in `block in from_symbol': unknown or unsupported macOS version: :dunno (MacOSVersionError)
from /usr/local/Homebrew/Library/Homebrew/os/mac/version.rb:33:in `fetch'
from /usr/local/Homebrew/Library/Homebrew/os/mac/version.rb:33:in `from_symbol'
from /usr/local/Homebrew/Library/Homebrew/os/mac.rb:28:in `version'
from /usr/local/Homebrew/Library/Homebrew/os/mac.rb:60:in `prerelease?'
from /usr/local/Homebrew/Library/Homebrew/os.rb:43:in `<module:OS>'
from /usr/local/Homebrew/Library/Homebrew/os.rb:7:in `<top (required)>'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /usr/local/Homebrew/Library/Homebrew/global.rb:80:in `<top (required)>'
from /usr/local/Homebrew/Library/Homebrew/brew.rb:31:in `require_relative'
from /usr/local/Homebrew/Library/Homebrew/brew.rb:31:in `<main>'
运行如下命令解决:
$ brew update-reset
打开book/book/guided-tour/examples/correct/sum/sum.ml 出现如下错误:
No config found for file "sum.ml" in ".". Try calling dune build. ocamllsp
Unbound module Baseo camllsp
在sum目录下运行命令即可:
dune build
运行完
–watch命令yyds
dune build --watch --terminal-persistence=clear-on-rebuild