:{ main = do > print("Hello"" /> :{ main = do > print("Hello"" /> :{ main = do > print("Hello""/>

How can I produce multiline code in utop?

279 Views Asked by At

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?

1

There are 1 best solutions below

0
Chris On BEST ANSWER

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 = ()