OCaml - List - Creating a list

As all programming languages, it is possible to create lists in OCaml.

So, let's see this, right now with new examples.
We will indeed create two functions, one of ints and another of strings.

For the ints:

#let number =  [1; 2; 3; 4];;
For the strings:
#let fruits =  ["apricot"; "raspberry"; "cherry"; "tomato"];;
As you can see, there is no need to tell to the interpreter the type of elements in the list.
It's automatic! smiley

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Refresh Type the characters you see in this picture. Type the characters you see in the picture; if you can't read them, submit the form and a new image will be generated. Not case sensitive.  Switch to audio verification.