4 Matching Annotations
  1. Jun 2025
    1. ./hello.byte

      Again, if you install OCaml natively in Windows, you can run: .\hello.exe

      Linux uses forward slash to separate directory and Windows uses backslash

    1. “A language that doesn’t affect the way you think about programming is not worth knowing.”

      This statement may be a bit misleading. Alan has never recommend ML language in his life, instead he indeed recommends to use LiSP language.

    1. Unix development in Windows

      I dig through the documentation and have written this guide for Windows user that don't want to use WSL

      Installing OCaml Natively on Windows Using PowerShell

      This guide explains how to set up a native OCaml development environment on Windows using PowerShell. You will install the latest PowerShell (pwsh), Git, and opam (the OCaml package manager) along with some essential OCaml-related tools. Finally, you will configure your PowerShell profile so OCaml is available every time you launch a new session.


      1. Install PowerShell

      PowerShell 7 is recommended since it comes with new features and improvements compared to Windows PowerShell 5.1. Note that PowerShell 7 installs as pwsh.exe (instead of the legacy powershell.exe).

      • Download and Install via MSI Package:<br /> Visit the Installing PowerShell on Windows (MSI Package) page on Microsoft Learn.<br /> Download the MSI package and follow the installation prompts. Once installed, launch PowerShell 7 by running pwsh.exe.

      2. Install Git

      Git is required as a dependency for many OCaml tools. Download the latest x64 setup for Windows:

      • Download Git for Windows:<br /> Go to the Git Downloads for Windows page and click the link to download the latest x64 version.

      3. Install opam

      opam is the OCaml package manager and is the recommended way to manage OCaml installations on Windows.

      Step 1: Install opam Using WinGet

      Open PowerShell 7 (pwsh.exe) and execute the following command:

      powershell winget install OCaml.opam

      Step 2: Initialize opam

      Once the installation completes, initialize opam with:

      powershell opam init

      During initialization, you will be asked two questions:

      • First Prompt: Select the recommended setting.
      • Second Prompt: When asked if you want to switch to another shell, choose No.

      Please note that the initialization process may take a while depending on your computer's performance.


      4. Install Essential Platform Tools

      After setting up opam, install additional OCaml tools that will improve your development experience. Run the following command in PowerShell:

      powershell opam install ocaml-lsp-server odoc ocamlformat utop

      Like before, the installation time may vary based on your system.


      5. Configure Your PowerShell Profile for OCaml

      To access your OCaml environment in every PowerShell session, you need to update your PowerShell profile.

      Temporary Session Command

      For the current session, you can load the opam environment by running:

      powershell (& opam env) -split '\r?\n' | ForEach-Object { Invoke-Expression $_ }

      This command sets up the OCaml-related environment variables for the active session only.

      Making the Configuration Persistent

      1. Locate Your PowerShell Profile File:<br /> Execute the following command to reveal the profile path:

        powershell $profile

        You might receive a path similar to:

        C:\Users\<username>\Documents\PowerShell\Microsoft.PowerShell_profile.ps1

      2. Edit (or Create) Your Profile File:

        • Open the file at the path above.

        • If the file does not exist, create a new file with the same name (Microsoft.PowerShell_profile.ps1).

        • Add the following line to the file:

          powershell (& opam env) -split '\r?\n' | ForEach-Object { Invoke-Expression $_ }

        • Save the file.

      Now, every time you launch PowerShell, the OCaml environment will be automatically configured.


      6. Verify Your Installation

      To verify that everything is set up correctly:

      1. Open a new PowerShell session.

      2. Launch the OCaml Read-Evaluate-Print Loop (REPL) by typing:

        powershell utop

      3. In the utop prompt, test with a simple expression:

        ocaml 21 + 43;;

        The REPL should evaluate the expression and return the corresponding result.


      References