-
4
pages
-
English
-
Documents
Description
OCaml E nvironment Set up Ocaml is avai lable for download here : http://caml.inri a.fr/download.en.h tmlThere are install ation instruct ions provided for Windows and Unix based operating s ystems. O nce installed, t ype ocaml in a ter minal windo w to start the inter active 'top leve l' OCam l env ironment. If top level starts up, y ou will see som ething like :Objective Caml version 3.10.0#Primitive Types The basic OCa ml t ypes are int, float, bool, char, string and unit (which is a return t ype similar to ' void' in C). When na ming values, we do not have to declare an y of these t ypes expli citly thanks to OCam l's t ype infer ence engine. So to nam e a charact er for exa mple, we u se th e let ke yword as follows:#let x = 'a';;In the inter active Top Leve l environ ment, the co mpiler will respond to the above state ment with :val x : char = 'a'This tells u s tha t the nam e x is as sociated with t ype char and holds the value ' a'.The state ment#let x = 2;;will define an integ er t ype with the value 2. If w e in tend to define a float, we u se the stat ement #let x = 2.0;;This is im portant to note especi ally because OCa ml is stati cally t yped, me aning we will not be able to simply convert x from an int to a float after it is defin ed. On a rela ted not e, the standard ari thmetic operators are not overloaded in OCam l as the y are in m any languages. Addition of in tegers is expressed using the s ymbol ' +' w hile the s ymbol ...
-
Publié par
-
Langue
English