DkML
Contents
About OCaml
There are a few webpages that you should bookmark as you learn about OCaml. The first is the official OCaml website's About OCaml which has a comprehensive list of features that OCaml provides (the sales pitch!), and a good summary of OCaml:
OCaml mixes power and pragmatism in a way that makes it ideal for building complex software systems. What makes OCaml special is that it occupies a sweet spot in programming language design. It provides a combination of efficiency, expressiveness, and practicality that is matched by no other language. That is in large part because OCaml is an elegant combination of language features that have been developed over the last 40 years.
Then we recommend reading the first five chapters of the online textbook OCaml Programming - Correct + Efficient + Beautiful. The textbook has Youtube videos that can be watched independently of the textbook. The textbook and the videos will guide you through the language and explore each of OCaml's major features.
Once you start writing your own code you will need to know where to look to find libraries (called packages in OCaml). We recommend browsing the packages at OCaml Packages since it is official, reasonably up-to-date and has most packages' documentation.
Finally, if you hit a roadblock the best place to go is the Discord chat rooms and ask your question on the #beginners channel:
About DkML
The DkML distribution is an open-source set of software that supports software development in pure OCaml. The distribution's strengths are its:
- full compatibility with OCaml standards like Opam, Dune and ocamlfind
- laser focus on "native" development (desktop software, mobile apps and embedded software) through support for the standard native compilers like Visual Studio and Xcode
- ease-of-use through simplified installers and simple productivity commands; high school students should be able to use it
- security through reproducibility, versioning and from-source builds
These alternatives may be better depending on your use case:
- Developing in a Javascript first environment? Have a look at Esy and Reason
- Developing operating system kernels? Have a look at Mirage OS
- Developing Linux server software like web servers? Plain old OCaml on Debian, etc. works well
- Writing compilers or proofs? Plain old OCaml works really well
- Wanting quick installations? Use anything but DkML! DkML will conduct from-source builds unless it can guarantee (and code sign) the binaries are reproducible. Today that means a lot of compiling.
DkML officially supports Windows 64-bit machines and is slated to support macOS machines.
The DkML installer will install the basic OCaml system that includes:
ocamlc
: The batch compilerocaml
: The toplevel system or REPL. There is also a full-featured toplevel; seeutop
belowocamlrun
: The runtime systemocamlopt
: The native-code compilerocamllex
,ocamlyacc
: Lexer and parser generatorsocamldep
: The dependency generatorocamldoc
: The documentation generatorocamldebug
: The debuggerocamlprof
: The profilerocamlmklib
: The mixed C/OCaml library maker
The OCaml platform tools will also be installed:
opam
: Opam, the standard package manager for OCamlutop
: UTop, the standard "toplevel" for interactively running OCaml codeocamllsp
: OCaml Language Server for use with OCaml friendly IDEs like Visual Studio Code and Emacsocamlformat
andocamlformat-rpc
: OCamlFormat, the standard auto-formatter for OCaml codeocp-indent
: ocp-indent, the standard indenter for mixed OCaml/non-OCaml documents
Sponsor
Thanks to the OCaml Software Foundation for its economic support of DkML.
How to Install
These instructions are currently only for Windows developers.
Requirements
- 64-bit Windows 10 or 64-bit Windows 11. More operating systems will be coming.
- A fast internet connection. You will be downloading tens of gigabytes of data.
- 30GB of disk space.
- Administrator access on your computer to install the Microsoft Visual Studio C compilers.
- You don't need to watch the installation, but you do need to keep your computer powered on for at least one and a half (1.5) hours. The DkML installer will be downloading and doing intensive compilation during these hours, and you are free to do other things on your computer while it downloads and compiles.
Installation Instructions
Before you run the installer:
- Make sure your Windows username does not contain a space character
(e.g. for
C:\Users\Jane Smith
, OCaml will not install properly).
Run the following in a terminal (either Windows PowerShell or Command Prompt):
winget install Microsoft.VisualStudio.2019.BuildTools --override "--wait --passive --installPath C:\VS --addProductLang En-us --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended"
winget install Git.Git
winget install Diskuv.OCaml
And then in a NEW terminal:
dkml init --system
Any problems installing? Be sure to read the latest DkML release notes.
And if the release notes aren't relevant to your issue, file a new issue.
Install is done! What next?
You have completed the installation of DkML. Let us try some of the things you can do right now.
-
Open PowerShell (press the Windows key ⊞, type "PowerShell" and then Open
Windows PowerShell
). Do not re-use an old PowerShell window since it will know nothing about the new installation you just did. -
Run the
utop
application.PS> utop > ─┬───────────────────────────────┬─ > │ Welcome to utop version 2.9.0 │ > └───────────────────────────────┘ > > Type #utop_help for help about using utop. > > ─( 19:03:24 )─< command 0 >─{ counter: 0 }─ > utop #
-
Now let us try to enter some basic OCaml expressions ... be sure to include the
;;
and then press ENTER after each line:utop #> 3.5 +. 6. ;; > - : float = 9.5 utop #> 30_000_000 / 300_000 ;; > - : int = 100 utop #> let square x = x * x ;; > val square : int -> int = fun utop #> square 2 ;; > - : int = 4 utop #> square (square 2) ;; > - : int = 16
-
You probably want to do a lot more than that! You may want to edit your code in a easy-to-use editor with syntax highlighting, type inspection and auto-complete (an "integrated development environment" or more simply an IDE). You may also want to use other people's code packages. Right now if you tried to use the
Graphics
package, for example, you will get an error:utop #> open Graphics ;; > Error: Unbound module Graphics
-
Leave the
utop
application by typing:utop #> #quit ;;
-
Continue with Beyond Basics, which is the next topic. It will tell you how to do important things like setting up your IDE. Please starting read it!