Search code examples
visual-studio-codecompilationocamlexecute

running many lines of ocaml code on vscode


I just started learning ocaml and I have a problem with my vscode.

I noticed that when i write too many lines of codes they won't be compiled, only some of them. For example in the 1st picture, it only gives the result of the 3 first lines, then for the variable "t" it doesn't do anything.

enter image description here

https://i.sstatic.net/qQeCZ.png

and how I do to run the code: CTRL + a then shift + enter

So I want to know how to run all the lines at once


Solution

  • Please note that in an OCaml source file, there is no need for ;; to separate top-level definitions.

    let x = 4
    let y = 5
    let z = 8
    

    Works just as well as:

    let x = 4;;
    let y = 5;;
    let z = 8;;
    

    The ;; is primarily used within REPLs like utop to indicate the end of an expression, but should never be necessary in an OCaml source file.

    If you remove those ;; tokens, and Ctrl-A, Shift-Enter, you will see the following in your VSCode Terminal output.

    # let x = 3
      let y = 5
      let z = 2
      let t = 5
      ;;
    val x : int = 3
    val y : int = 5
    val z : int = 2
    val t : int = 5
    #