Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Str module in OCaml top level?

Tags:

module

ocaml

I tried two commands to load Str Module in OCaml top level. The first command gives me the error "Cannot find file Str.cmo". I then tried to use the file i was using in top level with the second command. With that command i got "Reference to undefined global Str".

#load "Str.cmo";;

#use "my_file.ml";;

What do i need to do to successfully load Str module in OCaml top level.

like image 209
power_output Avatar asked May 29 '16 17:05

power_output


People also ask

What is top level in OCaml?

In short, the toplevel is OCaml's Read-Eval-Print-Loop (repl) allowing interative use of the OCaml system. You can consider the toplevel an alternative to compiling OCaml into an executable.

How do I get out of toplevel OCaml?

In a terminal window, type utop to start the interactive OCaml session, commonly called the toplevel. Press Control-D to exit the toplevel.

Does OCaml have a REPL?

This chapter describes the toplevel system for OCaml, that permits interactive use of the OCaml system through a read-eval-print loop (REPL). In this mode, the system repeatedly reads OCaml phrases from the input, then typechecks, compile and evaluate them, then prints the inferred type and result value, if any.

What is module in OCaml?

ocaml modules allow to package together data structures definitions and functions operating on them. This allow to reduce code size and name confusion, as any identifier can appear in different modules, with different meanings, without any interference.


2 Answers

# #use "topfind";;
# #require "str";;
like image 159
Louis Roché Avatar answered Oct 20 '22 14:10

Louis Roché


Modules are "archives", so they are .cma files, not .cmo:

# #load "str.cma";;
# Str.regexp;;
- : string -> Str.regexp = <fun>
like image 25
Jeffrey Scofield Avatar answered Oct 20 '22 16:10

Jeffrey Scofield