In Haskell we can enter multi-line code at the terminal, by enclosing it between " :{ " and " :} ". For example, typing
> :{ main = do
> print("Hello") :}
in ghci, we can then call main
. How can we do this in Ocaml on utop?
The comments addressed this quite well, but just so there is an answer, there is no magic. Both the traditional OCaml toplevel (invoked with simply ocaml
) and utop
will read in until they find a terminating ;;
token.
For example:
─( 17:36:11 )─< command 0 >───────────────────────────────────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # print_endline
"Hello, world!";;
Hello, world!
- : unit = ()
─( 17:36:11 )─< command 1 >───────────────────────────────────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # let msg = "Hello, world!"
in
print_endline msg;;
Hello, world!
- : unit = ()