logo image

Ocaml Hello World! 

Ocaml Hello World! 

   
   

Output:

Click on RUN button to see the output

OCaml Online Compiler

Write, Run & Share OCaml code online using OneCompiler's OCaml online compiler for free. It's one of the robust, feature-rich online compilers for OCaml language, running on the latest version 4. Getting started with the OneCompiler's OCaml compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as OCaml. OneCompiler also has reference programs, where you can look for the sampleprograms and start learning. Happy learning!!

About OCaml

OCaml is general purpose programming language with more importance to safety and expressiveness. With it's advanced type system, it helps to catch the mistakes in an efficient way. Hence this is used to develop applications/environments where a single mistake can cost millions and speed matters. It has good community support and rich set of development tools and libraries.

key features

  • Strongly typed functional language
  • Easy to learn
  • Very powerful type system
  • Automatic memory management
  • There is a seperate compilation of standalone applications.
  • Ocaml compiler can also produce machine codes
  • Multiple inheritance and parametric classes etc can be expressed in a simpler way
  • User can define algebraic data types

Data types

ClassificationData-types
Basic data typesintegers, floating point numbers, booleans, characters, strings.
Sophisticated data typestuples, arrays, lists, sets, hash tables, queues, stacks, data streams.

Note:

OCaml allows users to define new data types.

Variables

Variable is a name given to the storage area in order to manipulate them in our programs.

let varible-names = value

Loops

1. If:

If is performed when you need to choose expression based on a boolean-condition.

if boolean-condition then (* code if condition is true *)
  
if boolean-condition then (* code if condition is true*) else (* code if condition is false*)

2. While:

While is used to iterate a set of statements based on a condition. Usually while is preferred when number of ierations is not known in advance.

while boolean-condition do
  (* code *)
done

3. For:

For loop is used to iterate a set of statements for specific number of items.

for var = start-value to end-value do
  (* code *)
done
  
for var = start-value downto end-value do
  (* code *)
done

Help us with your feedback!

Reference Programs:

OCaml

No tags available for OCaml

How to use?

Choose the language in which you want to run your program, by clicking the button next to Run. And then write your code in the code box, You can use the auto complete snippets and warnings and errors which helps you to write better code faster way.
Once you are done writing your code click the Run button, now the code will be submitted to OneCompiler and you will see the results in a second.

How to contribute?

Please fork OneCompiler repository and contribute us by adding more languages or the features to the existing OneCompiler backend.
You can also contibute to the community by adding more programs which users can search and use as base code for their programs.

API & More

You can embed OneCompiler into your own website. That helps your website users to write and test their programs within your website.
If you want to run and see the results from your backend you can utilize the OneCompiler API by integrating it with your backend.