djskhdfjkql
djskhdfjkql

Reputation: 3

output keyword in OCaml

I would like to know what the keyword output means in OCaml.

I looked at the documentation which says :

val output : out_channel -> bytes -> int -> int -> unit

output oc buf pos len writes len characters from byte sequence buf, starting at offset pos, to the given output channel oc. Raise Invalid_argument "output" if pos and len do not designate a valid range of buf.

The problem is that I don't understand at all what of all this mean.

It would be very nice if you could provide a simple example of code where the keyword output is used.

Thank you !

Upvotes: 0

Views: 76

Answers (1)

Jeffrey Scofield
Jeffrey Scofield

Reputation: 66793

There is no keyword output. There is only a function named output that's in the Pervasives module.

The purpose of output is to write some bytes to an output channel.

If you choose printable bytes, and if your output channel is the standard output, you can see the result in a small test:

# let mybytes = Bytes.of_string "hello\n";;
val mybytes : bytes = Bytes.of_string "hello\n"
# output stdout mybytes 0 6;;
hello
- : unit = ()
#

To show that output is just an identifier (i.e., a name) and not a keyword, note that you can define your own value named output:

# let output = 3010;;
val output : int = 3010
#

This is not the case with real keywords such as then:

# let then = 3010;;
Error: Syntax error
#

Upvotes: 2

Related Questions