1

I understand that its return type is the string that is read but why does it need the parameter of type unit?

0

1 Answer 1

2

Every OCaml function takes one value and returns one value1. Since there are no meaningful values that read_line could take but it must take something, unit is provided.

And read_line must be a function, because some work has to be done when it's called.

Likewise, a function which performs an action but for which there is no meaningful return value typically returns unit in OCaml.

E.g.

# print_endline "Hello, world!";;
Hello, world!
- : unit = ()

1 That one return value may be another function, thus allowing us to create functions which take more than one argument.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.