title | description | created | updated |
---|---|---|---|
Ocaml |
Ocaml Programming language cheatsheet gives you a quick reference to code syntax with examples makes it handy while coding. |
2020-07-01 |
2020-07-01 |
print_string "Hello world!"
-
print_string : is used to print the given string
-
(*
Single line comments*)
-
(*
Multi*
line*
comment.*)
Classification | Data-types |
---|---|
Basic data types | int, float, bool, char, string, unit. |
Sophisticated data types | tuples, arrays, lists, sets, hash tables, queues, stacks, data streams. |
let varible-names = value
let a = 100;
if boolean-condition then (* code if condition is true *)
if boolean-condition then (* code if condition is true*) else (* code if condition is false*)
while boolean-condition do
(* code *)
done
for var = start-value to end-value do
(* code *)
done
for var = start-value downto end-value do
(* code *)
done
let listName= [item1;item2;item3]
let tupleName : datatype * datatype * ... = (value, value, ...);;
let funcName (arguments) =
(* code *)
funcName arguments
(* Defining the function*)
let sum a b =
(a+b)
(* calling a function)
sum 3 7