I recently got the book Real World Ocaml and I cannot even get past the installation. I followed the instructions on ocaml.org as they laid out. I ran each command in sequence, I probably have reinstalled it this way 4 times by now. I can compile ocaml but I absolutely cannot get core or base to work. I am running windows 11, and my opam list shows core, base, and utop.
I try to use # require βbaseβ;; does not work.
I try to create a .ocamlinit file, does not work.
I use dune build with core and base both in the dune file
No matter what I do, no matter how many reinstall these modules do not work. I am so lost.
Sorry you are having a rough onboarding experience! We will help, and if thereβs anything we can take away to improve the onboarding after helping , weβll do so!
Could you please post the textual output you get after these commands, and gives details (e.g., about where you have created the .ocamlinit file)?
Also, could you confirm you followed these installation instructions for windows ? Install OCaml
Hi, thank you!
-
I did install ocaml using that webpageβs instructions and have been coding and able to run ocaml without packages just fine. However, now that Iβm trying to get more advanced I am trying to get these packages and that has been my roadblock
-
The .ocamlinit file is in my C:\Users\User_Name directory
-
dune build will output :
File βbin/main.mlβ, line 1, characters 0-9:
1 | open Base;;
^^^^^^^^^
Error (warning 33 [unused-open]): unused open Base.
File βtest/test_test.mlβ, line 1, characters 0-9:
1 | open Base;;
^^^^^^^^^
Error (warning 33 [unused-open]): unused open Base.
PS C:\Users\Dominic\Desktop\Summer Learning\OCaml\test> dune runtest
File βtest/test_test.mlβ, line 1, characters 0-9:
1 | open Base;;
^^^^^^^^^
Error (warning 33 [unused-open]): unused open Base. -
trying to run my code with utop after doing # #require βbaseβ; using shift enter exits here:
utop # open Base;;
Error: Unbound module Base
β( 13:14:52 )β< command 12 >ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ{ counter: 0 }β
utop # open Core;;
Error: Unbound module Core
β( 14:27:25 )β< command 13 >ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ{ counter: 0 }βutop #
Note: please use triple-backticks to surround code samples to format them correctly. Eg
utop # open Base;;
- The .ocamlinit file is in my C:\Users\User_Name directory
I am fairly sure this is not correct. It should be something like %USERPROFILE%\AppData
. But Iβm unable to find any documentation on this. I recommend experimenting a bit to see what works.
Error (warning 33 [unused-open]): unused open Base.
This is correct. You opened the module but didnβt use it in the file so far, hence the warning. The warning goes away once you start using the stuff defined in Base
.
utop # open Base;;
Error: Unbound module Base
This is also correct. You didnβt βrequireβ the library before trying to open its module. Try:
$ utop -require base
utop # open Base;;;
EDIT: related issue? utop/init.ml does not respect XDG on Windows Β· Issue #451 Β· ocaml-community/utop Β· GitHub
PS C:\Users\User_Name\Desktop\test> (& opam env) -split '\r?\n' | ForEach-Object { Invoke-Expression $_ }
PS C:\Users\User_Name\Desktop\test> utop -require base
β( 15:33:57 )β< command 0 >ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ{ counter: 0 }β
utop # open Base;;
β( 15:34:11 )β< command 1 >βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ{ counter: 0 }βutop #
( 15:34:23 )β< command 0 >βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ{ counter: 0 }β
utop # open Base;;
Error: Unbound module Base
β( 15:34:23 )β< command 1 >βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ{ counter: 0 }β
utop # open Core;;
Error: Unbound module Core
β( 15:34:24 )β< command 2 >βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ{ counter: 0 }β
utop #
3+4 ;;
- : int = 7
β( 15:34:24 )β< command 3 >βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ{ counter: 0 }β
utop #
8 / 3 ;;
- : int = 2
β( 15:34:24 )β< command 4 >βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ{ counter: 0 }β
utop #
3.5 +. 6. ;;
- : float = 9.5
β( 15:34:24 )β< command 5 >βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ{ counter: 0 }β
utop #
3*5>14 ;;
- : bool = true
β( 15:34:24 )β< command 6 >βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ{ counter: 0 }β
utop #
let square x = x*x ;;
val square : int -> int = <fun>
β( 15:34:24 )β< command 7 >βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ{ counter: 0 }β
utop #
square 2 ;;
- : int = 4
β( 15:34:24 )β< command 8 >βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ{ counter: 0 }β
utop #
square (square 2) ;;
- : int = 16
β( 15:34:24 )β< command 9 >βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ{ counter: 0 }β
utop #
let ratio x y =
Float.of_int x /. Float.of_int y ;;
val ratio : int -> int -> float = <fun>
β( 15:34:25 )β< command 10 >ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ{ counter: 0 }β
utop #
ratio 4 7 ;;
- : float = 0.5714285714285714
β( 15:34:25 )β< command 11 >ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ{ counter: 0 }βutop #
I get an output but the modules are still unbound.
Also in reference to
This is correct. You opened the module but didnβt use it in the file so far, hence the warning. The warning goes away once you start using the stuff defined in
I heard this as well but $ dune runtest
or $ dune exec
test does not output the code like if I were to run it without core
and base
β is this expected?
β( 15:33:57 )β< command 0 >ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ{ counter: 0 }β
utop # open Base;;
β( 15:34:11 )β< command 1 >βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ{ counter: 0 }βutop #
( 15:34:23 )β< command 0 >βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ{ counter: 0 }β
utop # open Base;;
Error: Unbound module Base
I donβt understand this output. You opened Base
twice, the first time it worked and the second time it didnβt? Did you edit the utop output somehow?
I heard this as well but
$ dune runtest
or$ dune exec
test does not output the code like if I were to run it withoutcore
andbase
β is this expected?
I donβt know whatβs in the test so I donβt know what the output should be. Can you try this:
$ utop -require base
utop # open Base;;
utop # Fn.non;;
It should output the signature of base v0.15.0 Β· OCaml Package
(*Test Program*)
open Base;;
open Core;;
3+4 ;;
8 / 3 ;;
3.5 +. 6. ;;
3*5>14 ;;
let square x = x*x ;;
square 2 ;;
square (square 2) ;;
let ratio x y =
Float.of_int x /. Float.of_int y ;;
ratio 4 7 ;;
I was able to get outputs for this program before I added core and base but now it just gives the unused error. Only when I try to run the dune build
I donβt understand this output. You opened
Base
twice, the first time it worked and the second time it didnβt? Did you edit the utop output somehow?
The output is first when I open base with utop and then secondly when I try to run my program by pressing shift + enter
This is the output of what you asked:
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β Welcome to utop version 2.15.0 (using OCaml version 5.3.0)! β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Type #utop_help for help about using utop.
β( 17:17:31 )β< command 0 >ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ{ counter: 0 }β
utop # open Base;;
β( 17:17:31 )β< command 1 >ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ{ counter: 0 }β
utop # Fn.non;;
- : ('a -> bool/2) -> 'a -> bool/2 = <fun>
Soβ¦everything is working then. The outputs are exactly as expected. Base
is loaded. Youβre getting the βunusedβ error in your test program because youβre not actually using anything from Base
. All the operations and definitions in the test program are using basic arithmetic with ints and floats. If you do something like let is = Fn.non not;;
then you will be using something from Base
and the βunusedβ warning will go away.
Btw, Base
is Jane Streetβs portable, minimal version of their standard library. Core
has a bunch of extra stuff in it thatβs not very portable so they recommend that most people use Base
unless they actually need something from Core
.
We can use open!
instead of open
.
This suppress the unused warning.
Ah I see, I am not sure how I was getting outputs of the mathematical operations before⦠I may have gotten it mixed up in my head. I have added some Base functions and now I can execute and build the program. As well as some print statements.
Thanks for your patience!
Btw,
Base
is Jane Streetβs portable, minimal version of their standard library.Core
has a bunch of extra stuff in it thatβs not very portable so they recommend that most people useBase
unless they actually need something fromCore
.
Will note this, I have heard a lot of complaints about this book because they start you off my installing core when for the most part you use base in the beginning.
I think the book was originally written when there was only Core
. Base
came later as a more minimal and more portable, stand-alone foundation for Core
.