Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
#######
#
# E-scripts on ocaml.
#
# Note 1: use the eev command (defined in eev.el) and the
# ee alias (in my .zshrc) to execute parts of this file.
# Executing this file as a whole makes no sense.
# An introduction to eev can be found here:
#
#   (find-eev-quick-intro)
#   http://angg.twu.net/eev-intros/find-eev-quick-intro.html
#
# Note 2: be VERY careful and make sure you understand what
# you're doing.
#
# Note 3: If you use a shell other than zsh things like |&
# and the for loops may not work.
#
# Note 4: I always run as root.
#
# Note 5: some parts are too old and don't work anymore. Some
# never worked.
#
# Note 6: the definitions for the find-xxxfile commands are on my
# .emacs.
#
# Note 7: if you see a strange command check my .zshrc -- it may
# be defined there as a function or an alias.
#
# Note 8: the sections without dates are always older than the
# sections with dates.
#
# This file is at <http://angg.twu.net/e/ocaml.e>
#           or at <http://angg.twu.net/e/ocaml.e.html>.
#        See also <http://angg.twu.net/emacs.html>,
#                 <http://angg.twu.net/.emacs[.html]>,
#                 <http://angg.twu.net/.zshrc[.html]>,
#                 <http://angg.twu.net/escripts.html>,
#             and <http://angg.twu.net/>.
#
#######



# «.ocamlref-html»		(to "ocamlref-html")
# «.debian»			(to "debian")
# «.class»			(to "class")
# «.ocaml-doc»			(to "ocaml-doc")
# «.ocaml-interp»		(to "ocaml-interp")
# «.irc-channel»		(to "irc-channel")
# «.menhir»			(to "menhir")
# «.dune»			(to "dune")
# «.ocamllex»			(to "ocamllex")
# «.ocamldep»			(to "ocamldep")
# «.caml-mode»			(to "caml-mode")
# «.tuareg»			(to "tuareg")
# «.tuareg-git»			(to "tuareg-git")
# «.tuareg-marmalade»		(to "tuareg-marmalade")
# «.tuareg»			(to "tuareg")
# «.tutorials»			(to "tutorials")
# «.janestreetcore-git»		(to "janestreetcore-git")
# «.utop»			(to "utop")
# «.ctfp»			(to "ctfp")
# «.ocaml-book-en»		(to "ocaml-book-en")
# «.typer»			(to "typer")
# «.typer-cuc»			(to "typer-cuc")
# «.implementing-functor»	(to "implementing-functor")
# «.tylr»			(to "tylr")
# «.first-hour»			(to "first-hour")
# «.first-hour-graphics»	(to "first-hour-graphics")
# «.pipe»			(to "pipe")
# «.michael-ryan-clarkson»	(to "michael-ryan-clarkson")
# «.lua-and-ocaml»		(to "lua-and-ocaml")
# «.ocaml-canvas»		(to "ocaml-canvas")
# «.error-unbound-module»	(to "error-unbound-module")
# «.metaocaml»			(to "metaocaml")
#
# «.Async»			(to "Async")
# «.class»			(to "class")
# «.comments»			(to "comments")
# «.core»			(to "core")
# «.debugging»			(to "debugging")
# «.exception»			(to "exception")
# «.explicit-types»		(to "explicit-types")
# «.feather»			(to "feather")
# «.Fmt»			(to "Fmt")
# «.find-ocamldoc»		(to "find-ocamldoc")
# «.fold»			(to "fold")
# «.functions»			(to "functions")
# «.identifiers»		(to "identifiers")
# «.include»			(to "include")
# «.init-file»			(to "init-file")
# «.label-name»			(to "label-name")
# «.let»			(to "let")
# «.libref»			(to "libref")
# «.list»			(to "list")
# «.load»			(to "load")
# «.match»			(to "match")
# «.merlin»			(to "merlin")
# «.module»			(to "module")
# «.ocamlbuild»			(to "ocamlbuild")
# «.ocamlmktop»			(to "ocamlmktop")
# «.odig»			(to "odig")
# «.opam»			(to "opam")
# «.opam-core»			(to "opam-core")
# «.opam-env»			(to "opam-env")
# «.opam-init»			(to "opam-init")
# «.opam-install»		(to "opam-install")
# «.open»			(to "open")
# «.printf»			(to "printf")
# «.record»			(to "record")
# «.refs»			(to "refs")
# «.shexp»			(to "shexp")
# «.stdlib»			(to "stdlib")
# «.strings»			(to "strings")
# «.topfind»			(to "topfind")
# «.toplevel»			(to "toplevel")
# «.type»			(to "type")
# «.use»			(to "use")




#####
#
# ocamlref-html
# 2025oct29
#
#####

# «ocamlref-html»  (to ".ocamlref-html")






#####
#
# debian
# 2025oct29
#
#####

# «debian»  (to ".debian")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
apti ocaml
apti ocaml-doc

# (find-zsh "installeddebs | sort | grep ocaml")
# (find-zsh "availabledebs | sort | grep ocaml")

# (find-status   "ocaml-base-nox")
# (find-vldifile "ocaml-base-nox.list")
# (find-udfile   "ocaml-base-nox/")
# (find-status   "ocaml-base")
# (find-vldifile "ocaml-base.list")
# (find-udfile   "ocaml-base/")
# (find-status   "ocaml-interp")
# (find-vldifile "ocaml-interp.list")
# (find-udfile   "ocaml-interp/")
# (find-status   "ocaml-mode")
# (find-vldifile "ocaml-mode.list")
# (find-udfile   "ocaml-mode/")
# (find-status   "ocaml-nox")
# (find-vldifile "ocaml-nox.list")
# (find-udfile   "ocaml-nox/")
# (find-status   "ocaml")
# (find-vldifile "ocaml.list")
# (find-udfile   "ocaml/")

# (find-status   "ocaml-man")
# (find-vldifile "ocaml-man.list")
# (find-udfile   "ocaml-man/")
# (find-status   "ocaml-compiler-libs")
# (find-vldifile "ocaml-compiler-libs.list")
# (find-udfile   "ocaml-compiler-libs/")




#####
#
# class
# 2025oct29
#
#####

# «class»  (to ".class")
# (find-ocamldoc "objectexamples")
# (find-ocamldoc "objectexamples#s:initializers")
# (find-books "__comp/__comp.el" "ocamlref" "45" "Objects in OCaml")

* (eepitch-ocaml)
* (eepitch-kill)
* (eepitch-ocaml)

class ab = object val mutable a = 0; method get_a = a; method set_a new_a = a <- new_a; end;;
let myab = new ab;;
myab#get_a;;
myab#set_a 42;;
myab#get_a;;


class point =
  object
    val mutable x = 0
    method get_x = x
    method move d = x <- x + d
  end;;

let p = new point;;
p#get_x;;
p#move 3;;
p#get_x;;

let x0 = ref 0;;

new point#get_x;;
new point#get_x;;

class point = fun x_init ->
  object
    val mutable x = x_init
    method get_x = x
    method move d = x <- x + d
  end;;

class point :
  int ->
  object val mutable x : int method get_x : int method move : int -> unit end
Like in function definitions, the definition above can be abbreviated as:
# class point x_init =
#   object
#     val mutable x = x_init
#     method get_x = x
#     method move d = x <- x + d
#   end;;
Chapter 3. Objects in OCaml                                                                      47

class point :
  int ->
  object val mutable x : int method get_x : int method move : int -> unit end
An instance of the class point is now a function that expects an initial parameter to create a point
object:
# new point;;
- : int -> point = <fun>

# let p = new point 7;;
val p : point = <obj>
The parameter x_init is, of course, visible in the whole body of the definition, including methods.
For instance, the method get_offset in the class below returns the position of the object relative
to its initial position.
# class point x_init =
#   object
#     val mutable x = x_init
#     method get_x = x
#     method get_offset = x - x_init
#     method move d = x <- x + d
#   end;;
class point :
  int ->
  object
    val mutable x : int
    method get_offset : int
    method get_x : int
    method move : int -> unit
  end
Expressions can be evaluated and bound before defining the object body of the class. This is useful
to enforce invariants. For instance, points can be automatically adjusted to the nearest point on a
grid, as follows:
# class adjusted_point x_init =
#   let origin = (x_init / 10) * 10 in
#   object
#     val mutable x = origin
#     method get_x = x
#     method get_offset = x - origin
#     method move d = x <- x + d
#   end;;
class adjusted_point :
  int ->
  object
    val mutable x : int
    method get_offset : int
48

    method get_x : int
    method move : int -> unit
  end




#####
#
# ocaml-doc (non-free - obsolete)
# 2019feb21
#
#####

# «ocaml-doc» (to ".ocaml-doc")
# (find-angg ".emacs" "ocaml")
# https://packages.debian.org/sid/ocaml-doc

* (eepitch-ocaml)
* (eepitch-kill)
* (eepitch-ocaml)
1+2*3;;
let pi = 4.0 *. atan 1.0;;
let square x = x *. x;;
square (sin pi) +. square (cos pi);;
1.0 * 2;;
let rec fib n =
  if n < 2 then n else fib (n-1) + fib (n-2);;
fib 10;;





#####
#
# ocaml-interp
# 2019feb21
#
#####

# «ocaml-interp» (to ".ocaml-interp")
# (find-es "ml" "ocaml")

# (find-fline "/usr/bin/ocaml")
# (find-fline "/usr/share/pixmaps/ocaml.xpm")
# (find-fline "/usr/share/menu/ocaml-interp")
# (find-udfile "ocaml-interp/copyright")
# (find-man "1 ocaml")
# (find-udfile "ocaml-interp/changelog.Debian.gz")

* (eepitch-ocaml)
* (eepitch-kill)
* (eepitch-ocaml)



#####
#
# irc-channel
# 2022oct05
#
#####

# «irc-channel»  (to ".irc-channel")
# (find-angg "elisp/test.el" "ee-rcirc-connect")
# (find-efunction 'find-erclibera)
# On libera:

*** 480 #ocaml Cannot join channel (+S) - SSL/TLS required
(edrx) 




#####
#
# menhir
# 2019sep21 / 2022mar17
#
#####

# «menhir» (to ".menhir")
# (find-zsh "installeddebs | sort | grep menhir")
# (find-zsh "availabledebs | sort | grep menhir")
# (find-status   "menhir")
# (find-vldifile "menhir.list")
# (find-udfile   "menhir/")
# (find-status   "menhir-doc")
# (find-vldifile "menhir-doc.list")
# (find-udfile   "menhir-doc/")
# (code-pdf-page "menhir" "/usr/share/doc/menhir/manual.pdf.gz")
# (code-pdf-text "menhir" "/usr/share/doc/menhir/manual.pdf.gz")
# (find-menhirpage)
# (find-menhirtext)

apti menhir menhir-doc




#####
#
# dune
# 2022mar17
#
#####

# «dune»  (to ".dune")
# (find-status   "ocaml-dune")
# (find-vldifile "ocaml-dune.list")
# (find-udfile   "ocaml-dune/")
# (find-sh "apt-file search dune | grep ocaml")
# (find-zsh "availabledebs | sort | grep dune")
# https://github.com/ocaml/dune
# (find-git-links "https://github.com/ocaml/dune" "dune")
# (code-c-d "dune" "~/usrc/dune/")
# (find-dunefile "")
# (find-dunefile "doc/")
# (find-dunefile "example/")




#####
#
# ocamllex
# 2022mar17
#
#####

# «ocamllex»  (to ".ocamllex")
# (find-ocamlrefpage (+ 2 271) "13" "Lexer and parser generators")
# (find-ocamlreftext (+ 2 271) "13" "Lexer and parser generators")
# (find-status   "ocaml-nox")
# (find-vldifile "ocaml-nox.list")
# (find-udfile   "ocaml-nox/")
# (find-man "1 ocamllex")



#####
#
# ocamldep
# 2022mar17
#
#####

# «ocamldep»  (to ".ocamldep")
# (find-ocamlrefpage (+ 2 285) "14" "Dependency generator (ocamldep)")
# (find-ocamlreftext (+ 2 285) "14" "Dependency generator (ocamldep)")
# (find-man "1 ocamldep")





#####
#
# plzoo-git
# 2019aug29
#
#####

# «plzoo-git» (to ".plzoo-git")
# (find-es "ml" "plzoo-git")
# https://github.com/andrejbauer/plzoo

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
rm -Rfv ~/usrc/plzoo/
cd      ~/usrc/
git clone https://github.com/andrejbauer/plzoo
cd      ~/usrc/plzoo/

git branch --list -a
git for-each-ref
PAGER=cat git log --oneline --graph --all -20

make     |& tee om
make all |& tee om

# (find-fline "~/usrc/")
# (find-fline "~/usrc/plzoo/")
# (find-gitk  "~/usrc/plzoo/")

# (code-c-d "plzoo" "~/usrc/plzoo/")
# (find-plzoofile "")
# (find-plzoofile "src/")
# (find-plzoofile "src/lambda/")
# (find-plzoofile "src/levy/")




#####
#
# caml-mode
# 2019sep21
#
#####

# «caml-mode» (to ".caml-mode")
# (find-es "ml" "ocaml-mode")
# (find-epackages "\n  caml " t)
# (find-epackage 'caml)
# (find-elpafile "caml-readme.txt")
# (find-elpafile "caml-20190413.1205/")
# https://github.com/ocaml/ocaml/

# (code-c-d "camlmode" "~/.emacs.d/elpa/caml-20190413.1205/")
# (find-camlmodefile "")




#####
#
# tuareg
# 2022mar17
#
#####

# «tuareg»  (to ".tuareg")
# (find-epackage-links 'tuareg "tuareg" t)
# (find-epackage       'tuareg)
# (code-c-d "tuareg" "~/.emacs.d/elpa/tuareg-20250909.1604/")
# (find-tuaregfile "")
# (find-tuaregfile "tuareg.el")
# (find-tuaregfile "tuareg-autoloads.el" "(add-to-list 'auto-mode-alist ")
# https://github.com/ocaml/tuareg



#####
#
# tuareg-git
# 2019sep21
#
#####

# «tuareg-git» (to ".tuareg-git")
# (find-es "ml" "ocaml-mode")
# http://www.emacswiki.org/emacs/TuaregMode ->
# http://tuareg.forge.ocamlcore.org/ ->
# https://github.com/ocaml/tuareg

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
rm -Rfv ~/usrc/tuareg/
cd      ~/usrc/
git clone https://github.com/ocaml/tuareg
cd      ~/usrc/tuareg/

git branch --list -a
git for-each-ref
PAGER=cat git log --oneline --graph --all -20

# (find-fline "~/usrc/")
# (find-fline "~/usrc/tuareg/")
# (find-gitk  "~/usrc/tuareg/")

# (code-c-d "tuareggit" "~/usrc/tuareg/")
# (find-tuaregfile "")
# (find-tuareggitfile "")
# (find-tuareggitfile "README.md")
# (find-tuareggitfile "tuareg-site-file.el")
# (find-tuareggitfile "tuareg.el" "M-x tuareg-run-ocaml")
# (find-tuareggitgrep "grep --color -nH -e run-ocaml *.el")

# (load "~/usrc/tuareg/tuareg-site-file")





#####
#
# tuareg-marmalade (obsolete)
# 2019sep21
#
#####

# «tuareg-marmalade» (to ".tuareg-marmalade")
# (find-es "emacs" "marmalade")
# https://marmalade-repo.org/
# https://marmalade-repo.org/packages/tuareg
# https://forge.ocamlcore.org/projects/tuareg/
# https://forge.ocamlcore.org/tracker/?group_id=43
# http://melpa.org/#/tuareg

(package-refresh-contents)
;; (find-evardescr 'package-archives)
(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))
(package-refresh-contents)

M-x package-refresh-contents [RET]
M-: (add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))
M-x package-refresh-contents [RET]
M-x package-install [RET] marmalade-demo
(find-epackage-links 'tuareg)

;; (find-fline "~/.emacs.d/elpa/tuareg-20190805.958/")
(code-c-d "tuareg" "~/.emacs.d/elpa/tuareg-20190805.958/")
;; (find-tuaregfile "")




#####
#
# tuareg
# 2019nov30
#
#####

# «tuareg» (to ".tuareg")
# (find-efunctiondescr 'tuareg-mode)
# (find-efunction      'tuareg-mode)
# (find-ekeymapdescr tuareg-mode-map)
# (find-ekeymapdescr tuareg-interactive-mode-map)
# (find-tuaregfile "")
# (find-tuareggitfile "")
# (find-tuareggitfile "README.md")
# (find-tuareggitfile "README.md" "M-x run-ocaml")
# (find-efunctiondescr 'run-ocaml)
# (find-efunction      'run-ocaml)

# (find-tuareggrep "grep --color -nH --null -e tuareg-eval-phrase *.el")
# (find-tuaregfile "tuareg.el" "(defun tuareg-eval-phrase ()")




#####
#
# tutorials
# 2019sep21
#
#####

# «tutorials» (to ".tutorials")
# https://ocaml.org/docs
# https://ocaml.org/learn/tutorials/
# https://ocaml.org/learn/tutorials/basics.html




#####
#
# janestreetcore-git
# 2019nov30
#
#####

# «janestreetcore-git» (to ".janestreetcore-git")
# (find-git-links "https://github.com/janestreet/core" "janestreetcoregit")
# https://github.com/janestreet/core

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
# rm -Rfv ~/usrc/core/
cd      ~/usrc/
git clone https://github.com/janestreet/core
cd      ~/usrc/core/

# (find-fline "~/usrc/")
# (find-fline "~/usrc/core/")
# (find-gitk  "~/usrc/core/")

# (code-c-d "janestreetcoregit" "~/usrc/core/")
# (find-janestreetcoregitfile "")




https://github.com/janestreet/core
https://opensource.janestreet.com/core/
https://ocaml.janestreet.com/ocaml-core/v0.12/doc/
https://opam.ocaml.org/packages/core/
https://discuss.ocaml.org/t/documentation-on-jane-street-core/200








#####
#
# utop
# 2019sep21
#
#####

# «utop» (to ".utop")
# (find-opam-links "utop")
# https://opam.ocaml.org/blog/about-utop/
# https://opam.ocaml.org/packages/utop/
# (find-status   "utop")
# (find-vldifile "utop.list")
# (find-udfile   "utop/")
# (find-fline "/etc/emacs/site-start.d/50utop.el")

# (find-man "utop")
# (find-fline "~/.opam/packages/utop/utop.2.2.0/")

https://ocaml.org/learn/books.html

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
utop
#utop_help




#####
#
# Category Theory for Programmers - OCaml edition
# 2020feb16
#
#####

# «ctfp» (to ".ctfp")
# https://github.com/hmemcpy/milewski-ctfp-pdf/
# https://github.com/hmemcpy/milewski-ctfp-pdf/releases/tag/v1.4.0-rc1
# https://github.com/hmemcpy/milewski-ctfp-pdf/releases/download/v1.4.0-rc1/category-theory-for-programmers-ocaml.pdf

(code-pdf-page "ctfpocaml" "$S/https/github.com/hmemcpy/milewski-ctfp-pdf/releases/download/v1.4.0-rc1/category-theory-for-programmers-ocaml.pdf")
(code-pdf-text "ctfpocaml" "$S/https/github.com/hmemcpy/milewski-ctfp-pdf/releases/download/v1.4.0-rc1/category-theory-for-programmers-ocaml.pdf")
;; (find-ctfpocamlpage)
;; (find-ctfpocamlpage 3 "Contents")
;; (find-ctfpocamltext 3 "Contents")
;; (find-ctfpocamltext)




#####
#
# ocaml-book-en - Developing applications with Objective Caml (O'Reilly, 2000)
# 2020may09
#
#####

# «ocaml-book-en» (to ".ocaml-book-en")
# (find-status   "ocaml-book-en")
# (find-vldifile "ocaml-book-en.list")
# (find-udfile   "ocaml-book-en/")
# (code-pdf-page "ocamlorabook" "/usr/share/doc/ocaml-book/en/ocaml-ora-book.pdf")
# (code-pdf-text "ocamlorabook" "/usr/share/doc/ocaml-book/en/ocaml-ora-book.pdf")
# (find-ocamlorabookpage)
# (find-ocamlorabooktext)
# (find-ocamlorabookpage 7 "Contents")
# (find-ocamlorabooktext 7 "Contents")






#####
#
# typer
# 2020may09
#
#####

# «typer» (to ".typer")
# (find-books "__comp/__comp.el" "monnier-typer")
# http://www.iro.umontreal.ca/~monnier/

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
# rm -Rfv ~/usrc/typer/
cd      ~/usrc/
git clone https://gitlab.com/monnier/typer
cd      ~/usrc/typer/

# (find-gitk  "~/usrc/typer/")
# (code-c-d "typer" "~/usrc/typer/")
# (find-typerfile "")
# (find-typerfile ".travis.yml" "sudo apt-get install opam")
# (find-typerfile "GNUmakefile")
# (find-typerfile "README.md")
# (find-typersh "find * | sort")
# (find-typersh "find * | grep typer | sort")
# (find-typersh "find * | grep tex | sort")

apti opam
apti ocamlbuild
apti ocaml-findlib
apti libzarith-ocaml-dev libzarith-ocaml-doc
apti dune

git reset
make clean
cd      ~/usrc/typer/
make install

make tests

# (find-fline "~/usrc/typer/doc/formal/")
# (find-fline "~/usrc/typer/doc/formal/typer_theory.tex")
cd ~/usrc/typer/
git checkout master

cd ~/usrc/typer/doc/formal/
pdflatex typer_theory.tex
bibtex   typer_theory
pdflatex typer_theory.tex
pdflatex typer_theory.tex

# «typer-cuc»  (to ".typer-cuc")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
rm -Rfv ~/usrc/typer/
cd      ~/usrc/
git clone https://gitlab.com/monnier/typer
cd      ~/usrc/typer/
git checkout report/itd

# (find-fline "~/usrc/typer/")
# (find-typerfile "GNUmakefile")
# (find-typerfile "GNUmakefile" "bibexport")
# (find-typerfile "paper.tex")
# (find-typerfile "paper.tex" "\\caption{Mapping CUC to CIC}")
cd ~/usrc/typer/
pdflatex paper
bibtex   paper
pdflatex paper
pdflatex paper




Ooops, sorry (?)!
I just found about 50% of what I was looking for...

  mkdir -p ~/usrc/
  rm -Rfv  ~/usrc/typer/
  cd       ~/usrc/
  git clone https://gitlab.com/monnier/typer
  cd       ~/usrc/typer/
  cd       ~/usrc/typer/doc/formal/
  pdflatex typer_theory.tex
  bibtex   typer_theory
  pdflatex typer_theory.tex
  pdflatex typer_theory.tex

  # (code-c-d      "typertheory" "~/usrc/typer/doc/formal/")
  # (code-pdf-page "typertheory" "~/usrc/typer/doc/formal/typer_theory.pdf")
  # (code-pdf-text "typertheory" "~/usrc/typer/doc/formal/typer_theory.pdf")
  # (find-typertheoryfile "")
  # (find-typertheorypage)
  # (find-typertheorytext)

but if you can share the source of your Figure 12 in
<http://www.iro.umontreal.ca/~monnier/itd-tyde-2019.pdf#page=10>
that would be really great!

  Cheers =),
    Eduardo





#####
#
# implementing-functor
# 2021apr23
#
#####

# «implementing-functor»  (to ".implementing-functor")
# https://blog.0branch.com/posts/2012-03-26-01-implementing-functor-ocaml.html
# https://blog.0branch.com/posts/2012-03-26-02-from-functor.html




#####
#
# tylr
# 2022aug10
#
#####

# «tylr»  (to ".tylr")
# https://twitter.com/dm_0ney/status/1414742742530498566?s=20
# https://tylr.fun/
# https://github.com/hazelgrove/tylr
# (find-git-links "https://github.com/hazelgrove/tylr" "tylr")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
# rm -Rfv ~/bigsrc/tylr/
cd      ~/bigsrc/
git clone https://github.com/hazelgrove/tylr
cd      ~/bigsrc/tylr/

# (find-fline "~/bigsrc/")
# (find-fline "~/bigsrc/tylr/")
# (find-gitk  "~/bigsrc/tylr/")

# (code-c-d "tylr" "~/bigsrc/tylr/")
# (find-tylrfile "")
# (find-tylrfile "README.md")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
cd      ~/bigsrc/tylr/
make deps       # build dependencies (locked in opam.export)
make            # build tylr src
make echo-html  # echo path to compiled page

# file:///home/edrx/bigsrc/tylr/_build/default/src/web/www/index.html




#####
#
# A First Hour with OCaml
# 2022mar16
#
#####

# «first-hour»  (to ".first-hour")
# https://ocaml.org/learn/tutorials/a_first_hour_with_ocaml.html
# (brprinceurl "https://ocaml.org/learn/tutorials/a_first_hour_with_ocaml.html")
# (code-pdf-page "firsthour" "$S/https/ocaml.org/learn/tutorials/a_first_hour_with_ocaml.pdf")
# (code-pdf-text "firsthour" "$S/https/ocaml.org/learn/tutorials/a_first_hour_with_ocaml.pdf")
# (find-firsthourpage)
# (find-firsthourtext)

* (eepitch-ocaml)
* (eepitch-kill)
* (eepitch-ocaml)
50 * 50;;

(*# #use "program.ml"
*)

let x = 50;;
x * x;;
let x = 50 in x * x;;
let a   = 1 in
let b   = 2 in
    a + b;;
let square x = x * x;;
square 50;;

let square_is_even x =
    square x mod 2 = 0;;
square_is_even 50;;
square_is_even 3;;

let ordered a b c =
  a <= b && b <= c;;
ordered 1 1 2;;

let average a b =
    (a +. b) /. 2.0;;
1 +  2.5;;   (* err *)
1 +. 2.5;;   (* err *)
float_of_int 1 +. 2.5;;

let rec range a b =
    if a > b then []
    else a :: range (a + 1) b;;
let digits = range 0 9;;

(* (find-firsthourpage 5 "Types")
 * (find-firsthourtext   "Types")
*)
1 + 2;;
1.0 +. 2.0;;
false;;
'c';;
"Help me!";;

int_of_char;;

let rec factorial n =
  if n <= 1 then 1 else n * factorial (n - 1);;
let rec factorial n =
  match n with
  | 0 | 1 -> 1
  | x -> x * factorial (x - 1);;
let rec factorial n =
  match n with
  | 0 | 1 -> 1
  | _ -> n * factorial (n - 1);;
let rec factorial = function
  | 0 | 1 -> 1
  | n -> n * factorial (n - 1);;

(* (find-firsthourpage 7 "Lists")
 * (find-firsthourtext 7 "Lists")
*)

[];;
[1; 2; 3];;
[false; false; true];;
[[1; 2]; [3; 4]; [5; 6]];;
1 :: [2; 3];;
[1] @ [2; 3];;

let rec total l =
  match l with
  | [] -> 0
  | h :: t -> h + total t;;
total [1; 3; 5; 3; 1];;

let rec total_wrong l =
  match l with
  | h :: t -> h + total_wrong t;;  (* warning: not exhaustive *)

total_wrong [1; 3; 5; 3; 1];;

let rec length l =
  match l with
  | [] -> 0
  | _ :: t -> 1 + length t;;

length [1; 2; 3];;
length ["cow"; "sheep"; "cat"];;
length [[]];;

let rec append a b =
  match a with
  | [] -> b
  | h :: t -> h :: append t b;;

let rec map f l =
  match l with
  | [] -> []
  | h :: t -> f h :: map f t;;

map total [[1; 2]; [3; 4]; [5; 6]];;
map (fun x -> x * 2) [1; 2; 3];;

let add a b = a + b;;
add;;
let f = add 6;;
f 7;;
map (add 6) [1; 2; 3];;
map (map (fun x -> x * 2)) [[1; 2]; [3; 4]; [5; 6]];;

(* (find-firsthourpage 10 "Other built-in types")
 * (find-firsthourtext 10 "Other built-in types")
*)

let t = (1, "one", '1');;
type person =
  {first_name : string;
   surname : string;
   age : int};;
let frank =
  {first_name = "Frank";
   surname = "Smith";
   age = 40};;
let s = frank.surname;;
type colour = Red | Blue | Green | Yellow;;
let l = [Red; Blue; Red];;
type colour =
  | Red
  | Blue
  | Green
  | Yellow
  | RGB of int * int * int;;
let l = [Red; Blue; RGB (30, 255, 154)];;

type 'a tree =
  | Leaf
  | Node of 'a tree * 'a * 'a tree;;
let t =
  Node (Node (Leaf, 1, Leaf), 2, Node (Node (Leaf, 3, Leaf), 4, Leaf));;

let rec total t =
  match t with
  | Leaf -> 0
  | Node (l, x, r) -> total l + x + total r;;
let rec flip t =
  match t with
  | Leaf -> Leaf
  | Node (l, x, r) -> Node (flip r, x, flip l);;
let all = total t;;
let flipped = flip t;;
t = flip flipped;;

(* (find-firsthourpage 12 "Dealing with errors")
 * (find-firsthourtext 12 "Dealing with errors")
*)

exception E;;
exception E2 of string;;
let f a b =
  if b = 0 then raise (E2 "division by zero") else a / b;;
try f 10 0 with E2 _ -> 0;;
f 10 0;;
let f a b =
  if b = 0 then None else Some (a / b);;
let list_find_opt p l =
  try Some (List.find p l) with
    Not_found -> None;;
let list_find_opt p l =
  match List.find p l with
  | v -> Some v
  | exception Not_found -> None;;

* (eepitch-ocaml)
* (eepitch-kill)
* (eepitch-ocaml)

(* (find-firsthourpage 12 "Imperative OCaml")
 * (find-firsthourtext 12 "Imperative OCaml")
*)

let r = ref 0;;
r := 100;;
!r;;
let swap a b =
  let t = !a in
    a := !b;
    b := t;;
let print_number n =
  print_string (string_of_int n);
  print_newline ();;
print_newline;;
let table n =
  for row = 1 to n do
    for column = 1 to n do
      print_string (string_of_int (row * column));
      print_string " "
    done;
    print_newline ()
  done;;
let smallest_power_of_two x =
  let t = ref 1 in
    while !t < x do
      t := !t * 2
    done;
    !t;;
let arr = [|1; 2; 3|];;
arr.(0);;
arr.(0) <- 0;;
arr;;
type person =
  {first_name : string;
   surname : string;
   mutable age : int};;
let birthday p =
  p.age <- p.age + 1;;

(* (find-firsthourpage 15 "The Standard Library")
 * (find-firsthourtext 15 "The Standard Library")
*)

List.concat [[1; 2; 3]; [4; 5; 6]; [7; 8; 9]];;
List.filter (( < ) 10) [1; 4; 20; 10; 9; 2];;
List.sort compare [1; 6; 2; 2; 3; 56; 3; 2];;
let print_length s =
  Printf.printf "%s has %i characters\n" s (String.length s);;
List.iter print_length ["one"; "two"; "three"];;


** «first-hour-graphics»  (to ".first-hour-graphics")
**
* (eepitch-ocaml)
* (eepitch-kill)
* (eepitch-ocaml)
#use "topfind";;
#require "graphics";;
open Graphics;;
open_graph " 640x480";;

for i = 12 downto 1 do
  let radius = i * 20 in
    set_color (if i mod 2 = 0 then red else yellow);
    fill_circle 320 240 radius
done;;

read_line ();;

Random.self_init ();;

Graphics.open_graph " 640x480";;

set_color red;;

let rec iterate r x_init i =
  if i = 1 then x_init else
    let x = iterate r x_init (i - 1) in
      r *. x *. (1.0 -. x);;

for x = 0 to 639 do
  let r = 4.0 *. (float_of_int x) /. 640.0 in
  for i = 0 to 39 do
    let x_init = Random.float 1.0 in
    let x_final = iterate r x_init 500 in
    let y = int_of_float (x_final *. 480.) in
       Graphics.plot x y
  done
done;;

read_line ();;




#####
#
# pipe
# 2022oct05
#
#####

# «pipe»  (to ".pipe")
# (find-books "__comp/__comp.el" "ocaml")
# (find-books "__comp/__comp.el" "ocaml" "Pipe.transfer")
# (find-realworldocamlpage (+ 24 352)     "Pipe.transfer")
# (find-realworldocamltext (+ 24 352)     "Pipe.transfer")
# (find-anggfile "OCAML/PipeTest1.ml")

open Core.Std
open Async.Std


# (find-sh "locate -i ocaml | grep -i async")
# (find-sh "locate -i opam | grep -i async")




#####
#
# michael-ryan-clarkson
# 2022oct10
#
#####

# «michael-ryan-clarkson»  (to ".michael-ryan-clarkson")
# https://yewtu.be/playlist?list=PLre5AT9JnKShBOPeuiD9b-I4XROIJhkIU




#####
#
# lua-and-ocaml
# 2022nov01
#
#####

# «lua-and-ocaml»  (to ".lua-and-ocaml")
# https://stackoverflow.com/questions/405995/embedding-lua-in-ocaml?rq=1




#####
#
# ocaml-canvas
# 2022dec15
#
#####

# «ocaml-canvas»  (to ".ocaml-canvas")
# https://news.ycombinator.com/item?id=33954958 OCaml Canvas (ocamlpro.github.io)
# https://github.com/ocamlpro/ocaml-canvas
# https://ocamlpro.github.io/ocaml-canvas/
# https://ocamlpro.github.io/ocaml-canvas/sphinx/
# (code-c-d "ocamlcanvas" "~/usrc/ocaml-canvas/")
# (find-ocamlcanvasfile "")
# (find-ocamlcanvasfile "examples/")
# (find-ocamlcanvasfile "sphinx/")
# (find-opam-links "ocaml-canvas")
# (find-opamsourcesfile "ocaml-canvas.1.0.0/")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
opam update
opam upgrade
opam install ocaml-canvas

apti libxcb-image0-dev libxcb-keysyms1-dev libxcb-xkb-dev

# (find-fline "~/OCAML/canv.ml")





#####
#
# Error: Unbound module OcamlCanvas
# 2022dec17
#
#####

# «error-unbound-module»  (to ".error-unbound-module")
# https://discuss.ocaml.org/t/unbound-module-base-unbound-directive-require/8196/4

* (eepitch-ocaml)
* (eepitch-kill)
* (eepitch-ocaml)
#use "topfind";;
#list;;
#require "ocaml-canvas";;
#use "ocaml-canvas";;




#####
#
# metaocaml
# 2023apr21
#
#####

# «metaocaml»  (to ".metaocaml")
# (find-fline "~/LOGS/2023apr21.emacs" "MetaOCaml")
# https://okmij.org/ftp/ML/MetaOCaml.html
# https://okmij.org/ftp/meta-programming/



#####
#
# Async
# 2025oct29
#
#####

# «Async»  (to ".Async")
# (find-sh "locate -i async | grep -i ocaml")
# (find-sh "locate -i async | grep -i opam")
# (find-angg "OCAML/PipeTest1.ml")




#####
#
# class
# 2025nov02
#
#####

# «class»  (to ".class")
# (find-ocamldoc "objectexamples#s:classes-and-objects")
# (find-books "__comp/__comp.el" "ocaml" "227" "12. Classes")





#####
#
# comments
# 2019sep21
#
#####

# «comments» (to ".comments")
# (find-ocamlrefpage (+ 2 91) "6.1    Lexical conventions")
# (find-ocamlreftext (+ 2 91) "6.1    Lexical conventions")
# (find-ocamldoc "lex#sss:lex:comments")
# (find-eeit-links 'tuareg-mode)
# (find-eev "eev-testblocks.el" "tuareg-mode")
# (find-efunction 'ee-insert-test-tuareg-mode)





#####
#
# core
# 2025oct29
#
#####

# «core»  (to ".core")
# (find-opam-links "core")
# (code-c-d "core"    "~/.opam/default/.opam-switch/sources/core.v0.17.1/core/")
# (code-c-d "coresrc" "~/.opam/default/.opam-switch/sources/core.v0.17.1/core/src/")
# (find-coresrcfile "")
# (find-ocamlcorefile "src/string.ml")
# (find-fline "~/LOGS/2025nov02.ocaml")

# https://github.com/janestreet/core
# (find-git-links "https://github.com/janestreet/core" "core")
# (code-c-d "core"    "~/usrc/core/")
# (code-c-d "coresrc" "~/usrc/core/core/src/")
# (find-corefile "")
# (find-coresrcfile "")
# (find-corefile ".files.ml")
# (find-coresh "find * | sort")
# (find-coresh "find * | sort | grep '\\.ml$'")
# (find-coresh "du -ch *")
# (find-coregrep "grep --color=auto -nH --null -e 'module Stable' $(cat .files.ml)")
# (find-coregrep "grep --color=auto -nH --null -e module $(cat .files.ml)")
# (find-coregrep "grep --color=auto -nH --null -e iter $(cat .files.ml)")
# (find-coregrep "grep --color=auto -nH --null -e module $(cat .files.ml) | grep -ia sexp")
# (find-corefile "core/src/")
# (find-corefile "core/src/list0.ml")
# (find-corefile "core/src/list.ml")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
# rm -Rfv ~/usrc/core/
cd      ~/usrc/
git clone https://github.com/janestreet/core
cd      ~/usrc/core/

find * | sort | grep '\.ml$' | tee .files.ml



#####
#
# debugging
# 2025oct30
#
#####

# «debugging»  (to ".debugging")
# https://ocaml.org/docs/debugging
# https://ocaml.org/docs/debugging#the-ocaml-debugger




#####
#
# exception
# 2025nov05
#
#####

# «exception»  (to ".exception")
# (find-books "__comp/__comp.el" "ocaml" "128" "Exceptions")
# (find-ocamldoc "coreexamples#s:exceptions")
# (find-ocamldoc "libref/index_exceptions")




#####
#
# explicit-types
# 2025nov02
#
#####

# «explicit-types»  (to ".explicit-types")
# (find-books "__comp/__comp.el" "ocaml" "7" "adding explicit type annotations")
# (find-ocamldoc "lex#sss:lex:comments")





#####
#
# feather
# 2025oct30
#
#####

# «feather»  (to ".feather")
# https://ocaml.org/cookbook/read-and-write-text-file/stdlib
# https://ocaml.org/cookbook/run-piped-commands/feather
# https://ocaml.org/p/feather/latest




#####
#
# Fmt
# 2025oct29
#
#####

# «Fmt»  (to ".Fmt")
# (find-ocamldoc "api/Format")
# (find-ocamldoc "api/Fmt")
# (find-angg "OCAML/class-ab.ml")
# (find-fline "~/LOGS/2025oct29.ocaml" "let pp ppf r = Fmt.pf ppf")

<octachron> https://ocaml.org/manual/5.4/api/Format.html
<octachron> https://ocaml.org/p/fmt/latest for fmt

<octachron> For instance `let pp ppf r = Fmt.pf ppf "〘 a = %d 〙"
            r.a` `let () = Fmt.pr "Printing the record %a@." pp { a
            = 0 }`.

* (eepitch-ocaml)
* (eepitch-kill)
* (eepitch-ocaml)
open Fmt

Fmt.pf;;

let pp ppf r = Fmt.pf ppf "〘 a = %d 〙" r.a
let () = Fmt.pr "Printing the record %a@." pp { a = 0 };;




#####
#
# find-ocamldoc
# 2025oct29
#
#####

# «find-ocamldoc»  (to ".find-ocamldoc")
# (find-angg ".emacs" "ee-rstdoc-:ocaml")
# (find-angg ".emacs" "ee-rstdoc-:ocaml" "ocamldoc")
# (find-ocamldocfile "")
# (find-ocamldoc "objectexamples")
# (find-ocamldoc "objectexamples#s:initializers")
# (find-ocamldoc "api/Stdlib")
# (find-ocamldoc "api/Format")
# (find-fline "~/LOGS/2025oct29.ocaml" "The stdlib directory is called libref")

# https://ocaml.org/manual/5.4/index.html ->
# https://ocaml.org/releases/5.4/ocaml-5.4-refman-html.tar.gz

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
# (find-fline "~/usrc/ocamlref/")
rm -Rv ~/usrc/ocamlref/
mkdir  ~/usrc/ocamlref/
cd     ~/usrc/ocamlref/
tar -xvzf $S/https/ocaml.org/releases/5.4/ocaml-5.4-refman-html.tar.gz

# (find-fline "~/usrc/ocamlref/htmlman/")
# (find-fline "~/usrc/ocamlref/htmlman/api/")
rm -Rv    ~/usrc/ocamlref/htmlman/api/
mkdir     ~/usrc/ocamlref/htmlman/api/
cd        ~/usrc/ocamlref/htmlman/api/

cd /usr/share/doc/ocaml-doc/ocaml.html/libref/
cp -aRv * ~/usrc/ocamlref/htmlman/api/

# (find-ocamldocw "api/Stdlib")
# (find-ocamldoc "api/Stdlib")
# (find-ocamldoc "api/Format")
# (find-ocamldocw "api/Format")

https://ocaml.org/manual/5.4/api/Stdlib.html
# (find-ocamldoc "api/Stdlib")



#####
#
# fold
# 2025nov02
#
#####

# «fold»  (to ".fold")
# (find-ocamlstdlibgrep "grep --color=auto -nH --null -e fold *.ml")
# (find-ocamldoc "api/List")
# (find-ocamldoc "api/List#1_Iterators")

* (eepitch-ocaml)
* (eepitch-kill)
* (eepitch-ocaml)
List.fold_left max 10 [2;3;20];;
List.fold_left max 10 [2;3];;
List.fold_left max 10 [];;
#show_module List;;


List.fold_left max 0 (List.map String.length ["a";"bc"]);;

let lengths = List.map String.length ["a";"bc"] in
  List.fold_left max 0 lengths;;

("a" : string);;
(["a";"bc"] : string list);;







#####
#
# functions
# 2025nov02
#
#####

# «functions»  (to ".functions")
# (find-ocamldoc "coreexamples#s:functions-as-values")
# (find-books "__comp/__comp.el" "ocaml" "5" "Functions and Type Inference")
# (find-books "__comp/__comp.el" "ocaml" "31" "Functions")



#####
#
# identifiers
# 2025nov05
#
#####

# «identifiers»  (to ".identifiers")
# (find-ocamldoc "lex")
# (find-ocamldoc "lex#sss:lex:identifiers")
# (find-ocamldoc "lex#sss:lex-ops-symbols")




#####
#
# include
# 2025oct29
#
#####

# «include»  (to ".include")
# (find-ocamldoc "modules#sss:mexpr-include")
# (find-books "__comp/__comp.el" "ocaml" "79" "include Interval")

* (eepitch-ocaml)
* (eepitch-kill)
* (eepitch-ocaml)

module Interval = struct
  type t = | Interval of int * int
           | Empty
  let create low high =
    if high < low then Empty else Interval (low,high)
end;;

module Extended_interval = struct
  include Interval
  let contains t x =
    match t with
    | Empty -> false
    | Interval (low,high) -> x >= low && x <= high
end;;

Extended_interval.contains (Extended_interval.create 3 10) 4;;

module Extended_interval = struct
  open Interval
  let contains t x =
    match t with
    | Empty -> false
    | Interval (low,high) -> x >= low && x <= high
end;;






#####
#
# init-file
# 2025oct29
#
#####

# «init-file»  (to ".init-file")
# (find-man "1 ocaml")
# (find-man "1 ocaml" ".ocamlinit")
# (to "topfind")




#####
#
# label-name
# 2025nov01
#
#####

# «label-name»  (to ".label-name")
# (find-ocamldoc "lex#sss:labelname")
# (find-ocamldoc "expr#sss:expr-function-definition")
# (find-books "__comp/__comp.el" "ocaml" "11" "List.map languages ~f:String.length;;")
# (find-books "__comp/__comp.el" "ocaml" "40" "Labeled Arguments")




#####
#
# let
# 2025oct29
#
#####

# «let»  (to ".let")
# (find-ocamldoc "expr#start-section")
# (find-ocamldoc "expr#sss:expr-localdef")



#####
#
# libref
# 2025oct29
#
#####

# «libref»  (to ".libref")
# (find-fline "~/LOGS/2025oct29.ocaml" "The stdlib directory is called libref in the archive")
# (find-ocamlfile "")
# (find-fline "/usr/share/doc/ocaml-doc/ocaml.html/")
# (find-fline "/usr/share/doc/ocaml-doc/ocaml.html/libref/")
# (find-fline "/usr/share/doc/ocaml-doc/ocaml.html/libref/" "Format.html")
# (find-ocamldoc  "api/Format")
# (find-ocamldocw "api/Format")
# (find-ocamldocfile "api/" "Format")




#####
#
# list
# 2025nov02
#
#####

# «list»  (to ".list")
# (find-books "__comp/__comp.el" "ocaml" "11" "Lists")
# (find-ocamldoc "api/Stdlib.List")

# (find-opamgrep "grep --color=auto -nRH --null -e compare_length_with *")
# (find-opamfile "default/lib/ocaml/")
# (find-opamfile "default/lib/ocaml/list.ml" "let rec compare_length_with l n =")

* (eepitch-ocaml)
* (eepitch-kill)
* (eepitch-ocaml)
#help;;
#show_module List;;
#show_val List.map;;



#####
#
# Compiling a module and "#load"ing it from the toplevel
# 2025nov05
#
#####

# «load»  (to ".load")
# (find-angg "OCAML/test_load.ml")
# (find-ocamldoc "toplevel")
# (find-ocamldoc "toplevel#s:toplevel-directives" "#load")
# (find-ocamldoc "toplevel#s:toplevel-modules")
# (find-ocamldoc "comp#s:comp-overview")
# (find-ocamldoc "comp#s:comp-options" "-c" "Compile only")
# (find-man "1 ocamlc" "OPTIONS")
# (find-man "1 ocamlc" "-c     Compile only")
# (find-sh "ocamlc --help" "-c  Compile only (do not link)")





#####
#
# match
# 2025nov02
#
#####

# «match»  (to ".match")
# (find-books "__comp/__comp.el" "ocaml" "13" "List patterns using match")


#####
#
# merlin
# 2025nov05
#
#####

# «merlin»  (to ".merlin")
# https://github.com/ocaml/merlin
# https://ocaml.github.io/merlin/
# https://ocaml.github.io/merlin/editor/emacs/




#####
#
# module
# 2025nov01
#
#####

# «module»  (to ".module")
# (find-ocamldoc "moduleexamples#s:module:structures")
# (find-ocamldoc "api/index_modules")
# (to "open")
# (find-books "__comp/__comp.el" "ocaml" "76" "module Username :")



#####
#
# ocamlbuild
# 2022mar17
#
#####

# «ocamlbuild»  (to ".ocamlbuild")
# (find-ocamldoc "comp")
# (find-status   "ocamlbuild")
# (find-vldifile "ocamlbuild.list")
# (find-udfile   "ocamlbuild/")
# (find-udfile "ocamlbuild/examples/")
# (find-udfile "ocamlbuild/examples/01-simple/")
# (find-man  "1 ocamlbuild")
# (find-sh "ocamlbuild --help")
# (find-sh "ocamlc --help")

# (code-c-d "ocb" "/tmp/ocamlbuild01/")
# (find-ocbfile "")
# (find-ocbfile "Makefile")
# (find-ocbfile "_build/")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
rm -Rv /tmp/ocamlbuild01/
mkdir  /tmp/ocamlbuild01/
cd     /tmp/ocamlbuild01/
cp /usr/share/doc/ocamlbuild/examples/01-simple/* .

ocamlbuild main.byte
ocamlrun main.byte foo bar
./main.byte foo bar

laf 

ocamlbuild main.native

laf
make |& tee om
laf
make clean
laf
make native |& tee omn
make clean
laf
ocamlbuild main.native
./main.native foo bar
touch main.ml
ocamlbuild main.native
ocamlbuild main.byte
ocamlrun main.byte foo bar

make native |& tee omn


rm -Rv /tmp/ocamlbuild01/
mkdir  /tmp/ocamlbuild01/
cd     /tmp/ocamlbuild01/
cp /usr/share/doc/ocamlbuild/examples/01-simple/* .

ocamlbuild

ocamlc --help


# (find-fline "/usr/share/doc/ocamlbuild/examples/01-simple/")
# (find-fline "/tmp/ocamlbuild01/")
# (find-fline "/tmp/ocamlbuild01/om")
# (find-fline "/tmp/ocamlbuild01/_build/")
# (find-tuareggrep "grep --color=auto -nH --null -e _build *.el")
# (find-tuaregfile "tuareg.el" "(defun tuareg--switch-outside-build")







#####
#
# ocamlmktop
# 2025nov05
#
#####

# «ocamlmktop»  (to ".ocamlmktop")
# (find-man "ocamlmktop")
# https://discuss.ocaml.org/t/access-a-library-from-within-an-ocamlmktop-top-level/9133
# https://ocaml.org/docs/using-the-ocaml-compiler-toolchain#interlude-making-a-custom-toplevel
# https://hexmos.com/freedevtools/c/tools/ocamlmktop/




#####
#
# odig
# 2025oct29
#
#####

# «odig»  (to ".odig")
# https://opam.ocaml.org/packages/odig/
# (find-opam-links "odig")
# (find-fline "~/.opam/default/bin/" "odig")
# https://erratique.ch/software/odig
# https://github.com/b0-system/odig
# (find-git-links "https://github.com/b0-system/odig" "odig")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
w odig
odig readme
odig doc
odig doc odig
odig doc Format

file:///home/edrx/.opam/default/var/cache/odig/html/b0/index.html

# (find-man "odig")

odig doc           # Show API docs and manuals of installed packages
odig readme odig   # Consult the readme of odig
odig changes odig  # Consult the changelog of odig
odig browse issues odig  # Browse odig's issues.





# (find-git-links "https://github.com/b0-system/odig" "odig")
# (find-efunction 'find-git-links)

# (setq ee-git-dir "~/bigsrc/")
# (setq ee-git-dir "~/usrc/")
# (setq ee-git-dir "~/bigsrc/")
# (setq ee-git-dir "/tmp/")

# (find-fline "~/bigsrc/")
# (find-fline "~/bigsrc/odig/")

# https://github.com/b0-system/odig

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
rm -Rfv ~/bigsrc/odig/
cd      ~/bigsrc/
git clone https://github.com/b0-system/odig
cd      ~/bigsrc/odig/

export PAGER=cat
git branch --list -a
git for-each-ref
git log --oneline --graph --all -20

# (find-fline "~/bigsrc/")
# (find-fline "~/bigsrc/odig/")
# (find-gitk  "~/bigsrc/odig/")

# (code-c-d "odig" "~/bigsrc/odig/")
# (find-odigfile "")
# (find-odigsh "du -c .* *")






#####
#
# opam
# 2019sep21
#
#####

# «opam» (to ".opam")
# https://opam.ocaml.org/
# https://opam.ocaml.org/doc/Install.html
# https://opam.ocaml.org/doc/Install.html#Debian
# https://opam.ocaml.org/doc/Usage.html
# https://opam.ocaml.org/doc/Manual.html
# https://github.com/ocaml/opam

# (find-status   "opam")
# (find-vldifile "opam.list")
# (find-udfile   "opam/")
# (find-status   "opam-doc")
# (find-vldifile "opam-doc.list")
# (find-udfile   "opam-doc/")
# (find-fline "/usr/share/doc-base/opam-dev-man")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
export PAGER=cat
opam
opam help
# (find-sh "opam help")
# (find-sh "opam help | col -bx")
# (find-sh "opam help source | col -bx")

opam init
opam update
opam upgrade

opam info core
opam install core

# (find-anggfile ".ocamlinit" "Added by OPAM")

# (find-man "1 opam")
# (find-man "1 opam-admin-check")
# (find-man "1 opam-admin-depexts")
# (find-man "1 opam-admin-findlib")
# (find-man "1 opam-admin-make")
# (find-man "1 opam-admin-rename")
# (find-man "1 opam-admin-stats")
# (find-man "1 opam-admin")
# (find-man "1 opam-config")
# (find-man "1 opam-help")
# (find-man "1 opam-info")
# (find-man "1 opam-init")
# (find-man "1 opam-init" "-j JOBS, --jobs=JOBS")
# (find-man "1 opam-install")
# (find-man "1 opam-installer")
# (find-man "1 opam-lint")
# (find-man "1 opam-list")
# (find-man "1 opam-pin")
# (find-man "1 opam-reinstall")
# (find-man "1 opam-remote")
# (find-man "1 opam-remove")
# (find-man "1 opam-repository")
# (find-man "1 opam-search")
# (find-man "1 opam-show")
# (find-man "1 opam-source")
# (find-man "1 opam-switch")
# (find-man "1 opam-uninstall")
# (find-man "1 opam-unpin")
# (find-man "1 opam-update")
# (find-man "1 opam-upgrade")

(code-pdf-page "opam" "/usr/share/doc/opam-docs/dev-manual.pdf")
(code-pdf-text "opam" "/usr/share/doc/opam-docs/dev-manual.pdf")
(code-c-d      "opam" "~/.opam/")
;; (find-opampage)
;; (find-opamtext)
;; (find-opamfile "")
;; (find-opamsh "find * | sort")
;; (find-opamsh "du -c | sort -n")
;; (find-opamsh "find * | sort | grep utop")
# (find-fline "~/.opam/system/lib/utop/")




#####
#
# opam-env
# 2025oct30
#
#####

# «opam-env»  (to ".opam-env")
# (find-sh "opam env")
# (find-man "1 opam-env")
# (find-sh "opam env --shell=zsh")




#####
#
# opam-init
# 2019sep21
#
#####

# «opam-init» (to ".opam-init")
# (find-angg ".zshrc" "opam")
# (find-man "1 opam-init")
# (find-fline "~/.opam/")
# (find-fline "~/.opam/opam-init/")
# (find-fline "~/.opam/opam-init/init.zsh")
# (find-fline "~/.opam/opam-init/variables.sh")

# (code-c-d      "opam" "~/.opam/")
# (find-opamfile "")
# (find-opamsh "find * | sort")

In normal operation, OPAM only alters files within ~/.opam.

During this initialisation, you can allow OPAM to add information to two
other files for best results. You can also make these additions manually
if you wish.

If you agree, OPAM will modify:

  - ~/.zshrc (or a file you specify) to set the right environment
    variables and to load the auto-completion scripts for your shell (zsh)
    on startup. Specifically, it checks for and appends the following line:

    . /home/edrx/.opam/opam-init/init.zsh > /dev/null 2> /dev/null || true


  - ~/.ocamlinit to ensure that non-system installations of `ocamlfind`
    (i.e. those installed by OPAM) will work correctly when running the
    OCaml toplevel. It does this by adding $OCAML_TOPLEVEL_PATH to the list
    of include directories.

If you choose to not configure your system now, you can either configure
OPAM manually (instructions will be displayed) or launch the automatic setup
later by running:

   opam config setup -a


Do you want OPAM to modify ~/.zshrc and ~/.ocamlinit?
(default is 'no', use 'f' to name a file other than ~/.zshrc)
    [N/y/f] 

Global configuration:
  Updating ~/.opam/opam-init/init.sh
  Updating ~/.opam/opam-init/init.zsh
  Updating ~/.opam/opam-init/init.csh
  Updating ~/.opam/opam-init/init.fish

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

1. To configure OPAM in the current shell session, you need to run:

      eval `opam config env`

2. To correctly configure OPAM for subsequent use, add the following
   line to your profile file (for instance ~/.zshrc):

      . /home/edrx/.opam/opam-init/init.zsh > /dev/null 2> /dev/null || true

3. To avoid issues related to non-system installations of `ocamlfind`
   add the following lines to ~/.ocamlinit (create it if necessary):

      let () =
        try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH")
        with Not_found -> ()
      ;;

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=




#####
#
# opam-install
# 2025oct29
#
#####

# «opam-install»  (to ".opam-install")
# https://opam.ocaml.org/doc/Install.html
# https://opam.ocaml.org/doc/Upgrade_guide.html

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
cd /tmp/
sudo bash -c "sh <(curl -fsSL https://opam.ocaml.org/install.sh)"

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
# (find-fline "/tmp/opam-install/")
rm -Rv /tmp/opam-install/
mkdir  /tmp/opam-install/
cd     /tmp/opam-install/
wget https://opam.ocaml.org/install.sh
sudo bash ./install.sh

# (find-fline "/tmp/opam-local.aa.tmp")



* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
# (find-man "opam")
# (find-sh "du -ch ~/.opam")
rm -Rf ~/.opam/
export TERM=dumb
opam init
5
opam update
opam upgrade
opam switch create 4.08 ocaml-base-compiler.4.08.0
opam install odig

opam switch create --empty
opam switch create opam switch create 4.06 ocaml-base-compiler.4.06.0
opam switch create base-compiler

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)

# (find-sh "opam switch list-available --all")
# (find-sh "opam switch list-available")







#####
#
# Where opam stores a package ("core")
# 2019nov30
#
#####

# «opam-core» (to ".opam-core")
# (find-anggsh "find .opam/ | sort")
# (find-anggsh "find .opam/ | sort | grep core")
# (find-fline "~/.opam/")
# (find-fline "~/.opam/system/lib/core/")
# (find-fline "~/.opam/packages/")
# (find-fline "~/.opam/packages/" " core")
# (find-fline "~/.opam/packages/core/core.113.33.03/")
# (find-fline "~/.opam/packages/core/core.113.33.03/opam")
# (find-fline "~/.opam/packages/core/core.113.33.03/url")
# (find-fline "~/.opam/repo/default/packages/core/")
# (find-fline "~/.opam/repo/default/packages/core/core.113.33.03/")
# (find-fline "~/.opam/repo/default/packages/core/core.113.33.03/opam")
# (find-fline "~/.opam/repo/default/packages/core/core.113.33.03/url")
# (find-fline "~/.opam/archives/core.113.33.03+opam.tar.gz")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
# (find-fline "~/usrc/core.113.33.03/")
rm -Rv ~/usrc/core.113.33.03/
mkdir  ~/usrc/core.113.33.03/
cd     ~/usrc/
tar -xvzf ~/.opam/archives/core.113.33.03+opam.tar.gz
cd     ~/usrc/core.113.33.03/

# (code-c-d "janestreetcore" "~/usrc/core.113.33.03/")
# (find-janestreetcorefile "")





#####
#
# open
# 2025oct29
#
#####

# «open»  (to ".open")
# (to "toplevel")
# (find-ocamldoc "modules#sss:mexpr-open")
# (find-ocamldoc "expr#sss:local-opens")
# (find-ocamldoc "generalizedopens" "open!")
# (find-ocamldoc "overridingopen#s:explicit-overriding-open" "open!")

# (find-books "__comp/__comp.el" "ocaml" "3" "open Core.Std;;")
# (find-books "__comp/__comp.el" "ocaml" "77" "Opening Modules")
# (find-books "__comp/__comp.el" "ocaml" "77" "open M;;")

* (eepitch-ocaml)
* (eepitch-kill)
* (eepitch-ocaml)
module M = struct let foo = 3 end;;
foo;;    (* err *)
open M;;
foo;;



#####
#
# printf
# 2025nov02
#
#####

# «printf»  (to ".printf")
# (find-books "__comp/__comp.el" "ocaml" "104" "printf")
# (find-ocamlcoregrep "grep --color=auto -niH --null -e printf */*.ml")
# (find-ocamlcorefile "")
# (find-ocamlcorefile "src/printf.ml")
# (find-ocamldoc "libref/Printf")
# (find-ocamldoc "api/Printf")
# (find-opamfile "default/lib/base/printf.ml")
# (find-opamfile "default/lib/base/" "base__Printf")
# (find-sh "locate -i base | grep -i printf")
# (find-sh "locate -i stdlib | grep -i printf")

# (find-ocamlstdlibfile "")
# (find-ocamlstdlibfile "printf.ml")
# (find-ocamlstdlibfile "format.ml" "CamlinternalFormat.make_printf")

# (find-man "Stdlib.Printf")
# (find-sh "locate -i stdlib | grep -i printf")

* (eepitch-ocaml)
* (eepitch-kill)
* (eepitch-ocaml)
#use "topfind";;
#require "core";;
open Core;;
printf "_%s_" "ab";;






#####
#
# record
# 2025oct29
#
#####

# «record»  (to ".record")
# https://ocamlbook.org/records-and-references/
# (find-ocamldoc)
# (find-ocamldoc "coreexamples#s:tut-recvariants")
# (find-ocamldoc "coreexamples#ss:record-and-variant-disambiguation")
# (find-books "__comp/__comp.el" "ocaml" "18" "Records and Variants")

* (eepitch-ocaml)
* (eepitch-kill)
* (eepitch-ocaml)
type point2d = { x : float; y : float };;
let p = { x = 3.; y = -4. };;
let magnitude { x = x_pos; y = y_pos } = sqrt (x_pos ** 2. +. y_pos ** 2.);;
let magnitude { x; y } = sqrt (x ** 2. +. y ** 2.);;
let distance v1 v2 = magnitude { x = v1.x -. v2.x; y = v1.y -. v2.y };;

type circle_desc  = { center: point2d; radius: float }
type rect_desc    = { lower_left: point2d; width: float; height: float }
type segment_desc = { endpoint1: point2d; endpoint2: point2d } ;;

type scene_element =
  | Circle of circle_desc
  | Rect     of rect_desc
  | Segment of segment_desc
;;


* (eepitch-ocaml)
* (eepitch-kill)
* (eepitch-ocaml)
type ab  = { a : int; b : int };;
type abc = { a : int; b : int; c : int };;
let myab = { a=2; b=3 };;
let myab = { b=2; a=3 };;
let (myab : ab)  = { b=2; a=3 };;
let (myab : abc) = { b=2; a=3 };;   (* err *)

type cd = | C of int | D of int ;;
C 2;;





#####
#
# refs
# 2025nov02
#
#####

# «refs»  (to ".refs")
# (find-ocamldoc "api/Stdlib#1_References")
# (find-books "__comp/__comp.el" "ocaml" "22" "Refs")

* (eepitch-ocaml)
* (eepitch-kill)
* (eepitch-ocaml)
let x = ref 0;; 
!x;;
x := !x + 1;;
!x;;

type 'a ref = { mutable contents : 'a };;
let ref x = { contents = x };;
let (!) r = r.contents;;
let (:=) r x = r.contents <- x;;

* (eepitch-ocaml)
* (eepitch-kill)
* (eepitch-ocaml)
{ contonts = 42 };;
type 'a ref = { mutable contonts : 'a };;
{ contonts = 42 };;






#####
#
# shexp
# 2025oct30
#
#####

# «shexp»  (to ".shexp")
# https://ocaml.org/cookbook/run-piped-commands/shexp
# https://ocaml.org/p/shexp/latest
# (find-opam-links "shexp")
# (code-c-d "shexp" "~/.opam/default/.opam-switch/sources/shexp.v0.17.0/")
# (find-shexpfile "")
# (find-shexpfile "process-lib/examples/")
# (find-shexpfile "process-lib/examples/script.ml")
# (find-shexpfile "process-lib/src/")
# (find-shexpfile "process-lib/src/process.ml")





#####
#
# stdlib
# 2025oct29
#
#####

# «stdlib»  (to ".stdlib")
# (find-ocamldoc "api/Stdlib")
# (find-ocamldoc "api/Stdlib#modules")
# (find-books "__comp/__comp.el" "ocaml" "424" "stdlib/")
# (find-opamfile "default/lib/ocaml/")
# (find-opamfile "default/lib/ocaml/list.ml" "let rec compare_length_with l n =")

* (eepitch-ocaml)
* (eepitch-kill)
* (eepitch-ocaml)
open Core.Std
open Async.Std



#####
#
# strings
# 2025nov02
#
#####

# «strings»  (to ".strings")
# (find-ocamldoc "coreexamples#s:datatypes")
# (find-ocamlstdlibfile "string.ml")
# (find-ocamldoc "api/String")

* (eepitch-ocaml)
* (eepitch-kill)
* (eepitch-ocaml)
"ab\ncd";;
String.length "ab\ncd";;
String.split_on_char '\n' "ab\ncd";;





#####
#
# topfind
# 2025oct29
#
#####

# «topfind»  (to ".topfind")
# https://discuss.ocaml.org/t/what-does-use-topfind-do-and-why-do-i-need-it/11048
# (to "init-file")
# (find-sh "ocamlfind")
# (find-man "ocamlfind")
# (find-ocamlstdlib "topfind")

# (find-sh "locate ocamlfind")
# (find-sh "locate topfind")
# (code-c-d "findlib" "~/.opam/default/.opam-switch/sources/ocamlfind.1.9.8/src/findlib/")
# (find-findlibfile "")
# (find-findlibgrep "grep --color=auto -nH --null -e topfind *")
# (find-findlibgrep "grep --color=auto -nH --null -e 'Additional directives:' *")
# (find-findlibgrep "grep --color=auto -nH --null -e 'added to search path' *")
# (find-findlibgrep "grep --color=auto -nH --null -e 'dir_directory' *")
# (find-findlibgrep "grep --color=auto -nH --null -e 'module' *")
# (find-findlibgrep "grep --color=auto -niH --null -e 'topdirs' *")
# (find-findlibfile "")
# (find-findlibfile "topfind.in")
# (find-findlibfile "topfind.in" "#use \"topfind\"")
# (find-findlibfile "Makefile" "clean:")
# (find-findlibfile "topfind.ml.in" "let announce() =")

* (eepitch-ocaml)
* (eepitch-kill)
* (eepitch-ocaml)
#use "topfind";;
#list;;
#require "core";;
open Core;;
#show_module Topfind;;
#show_module Topdirs;;
#show_module Findlib;;
#show_module Fl_split;;

#show_val Findlib.package_directory;;

#list;;


#require "core/std";;




#####
#
# toplevel
# 2025nov01
#
#####

# «toplevel»  (to ".toplevel")
# (find-ocamldoc "toplevel")
# (find-ocamldoc "toplevel#s:toplevel-directives")

* (eepitch-ocaml)
* (eepitch-kill)
* (eepitch-ocaml)
#help;;
#show_module Stdlib;;




#####
#
# type
# 2025nov02
#
#####

# «type»  (to ".type")
# (find-books "__comp/__comp.el" "ocaml" "88" "type 'a timestamped = { item: 'a; time: Time.t };;")
# (find-ocamldoc "gadts-tutorial")




#####
#
# use
# 2025nov05
#
#####

# «use»  (to ".use")

* (eepitch-ocaml)
* (eepitch-kill)
* (eepitch-ocaml)
#help;;


https://github.com/clayrat/sequent-calc uses Levy

https://discuss.ocaml.org/t/interactive-ocaml-development-with-utop-in-emacs/6058
https://samarthkishor.github.io/posts/interactive_ocaml_development/
https://discuss.ocaml.org/t/ocaml-repl-driven-development/4068

Today was all about setting up Emacs for OCaml development.
https://kevinsjoberg.com/30-days-of-emacs-day-2

https://batsov.com/articles/2022/08/23/setting-up-emacs-for-ocaml-development/
https://batsov.com/articles/2022/08/19/learning-ocaml/
https://batsov.com/articles/2022/08/28/ocaml-tips-multiple-let-bindings/
https://batsov.com/articles/2022/08/29/ocaml-at-first-glance/
https://batsov.com/articles/2022/09/03/zipping-collections-in-ocaml/

https://news.ycombinator.com/item?id=32954517 OCaml Exercises (ocaml.org)

<edrx> hi all - I'm a beginner who has only followed some basic tutorials, but
       I haven't even used any libraries/modules yet...
<edrx> I'm wondering if it's easy to make ocaml call an external program -
       say, for an example/prototype, tac
<edrx> ...with a given input, and capture what it spits on stdout, and returns
       that as a string...
<edrx> where can I learn how do to that? any recommended links?
<edrx> actually the external program that I want to call is this one:
       http://angg.twu.net/eev-maxima.html#luatree




<><> ocp-indent.1.8.1 installed successfully ><><><><><><><><><><><><><><><><><>
=> This package requires additional configuration for use in editors. Install package 'user-setup', or
   manually:

   * for Emacs, add these lines to ~/.emacs:
     (add-to-list 'load-path "/home/edrx/.opam/default/share/emacs/site-lisp")
     (require 'ocp-indent)

   * for Vim, add this line to ~/.vimrc:
     set rtp^="/home/edrx/.opam/default/share/ocp-indent/vim"

<><> merlin.3.8.0 installed successfully ><><><><><><><><><><><><><><><><><><><>
=> merlin installed.

   Quick setup for VIM
   -------------------
   Append this to your .vimrc to add merlin to vim's runtime-path:
     let g:opamshare = substitute(system('opam var share'),'\n$','','''')
     execute "set rtp+=" . g:opamshare . "/merlin/vim"

   Also run the following line in vim to index the documentation:
     :execute "helptags " . g:opamshare . "/merlin/vim/doc"

   Quick setup for EMACS
   -------------------
   Add opam emacs directory to your load-path by appending this to your .emacs:
     (let ((opam-share (ignore-errors (car (process-lines "opam" "config" "var" "share")))))
      (when (and opam-share (file-directory-p opam-share))
       ;; Register Merlin
       (add-to-list 'load-path (expand-file-name "emacs/site-lisp" opam-share))
       (autoload 'merlin-mode "merlin" nil t nil)
       ;; Automatically start it in OCaml buffers
       (add-hook 'tuareg-mode-hook 'merlin-mode t)
       (add-hook 'caml-mode-hook 'merlin-mode t)
       ;; Use opam switch to lookup ocamlmerlin binary
       (setq merlin-command 'opam)))

   Take a look at https://github.com/ocaml/merlin for more information

   Quick setup with opam-user-setup
   --------------------------------

   Opam-user-setup support Merlin.

     $ opam user-setup install

   should take care of basic setup.
   See https://github.com/OCamlPro/opam-user-setup
# Run eval $(opam env) to update the current shell environment


https://sancho.dev/blog/learning-ocaml in 2023 ***
https://gist.github.com/Hirrolot/27e6b02a051df333811a23b97c375196 How to implement dependent types in 80 lines of code ***
https://borretti.me/article/design-austral-compiler
https://osa1.net/posts/2023-04-24-ocaml-thoughts.html
https://news.ycombinator.com/item?id=36094799 Oxidizing OCaml: Locality (janestreet.com)
https://tarides.com/blog/2024-05-29-effective-ml-through-merlin-s-destruct-command/
https://okmij.org/ftp/ML/generalization.html How OCaml type checker works -- or what polymorphism and garbage collection have in common ***
https://news.ycombinator.com/item?id=41281555 How the OCaml type checker works (2022) (okmij.org)
https://mmapped.blog/posts/41-box-combinators

https://cs3110.github.io/textbook/cover.html OCaml Programming: Correct + Efficient + Beautiful
https://news.ycombinator.com/item?id=44696979 OCaml Programming: Correct and Efficient and Beautiful (cs3110.github.io)



open Core.Std
open Async.Std


# (find-sh "locate -i core | grep -i std")

# (find-sh "du -ch ~/.opam/")
# (find-sh "rm -Rf ~/.opam/")


https://stackoverflow.com/questions/20577238/ocaml-how-to-see-modules-interface
https://discuss.ocaml.org/t/newbie-confused-by-ocaml-module-system/7363
https://discuss.ocaml.org/t/ocaml-repl-driven-development/4068/4
https://discuss.ocaml.org/t/ocaml-repl-driven-development/4068/4#basic-workflow-2
https://ocaml.org/docs/set-up-editor
https://ocaml.org/docs/set-up-editor#emacs
https://ocaml.org/docs/set-up-editor#lsp-setup-for-ocaml




#  Local Variables:
#  coding:               utf-8-unix
#  End: