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?
:{ main = do > print("Hello"" /> :{ main = do > print("Hello"" /> :{ main = do > print("Hello""/>
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) andutopwill read in until they find a terminating;;token.For example: