4

let i = 32 will give me a int32.

What if I want to define a int64?

Thomash
  • 6,339
  • 1
  • 30
  • 50
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271

3 Answers3

11
let i = 32L 

(Postfix L for int64 literals introduced in Objective Caml 3.07)

and use module Int64: http://caml.inria.fr/pub/docs/manual-ocaml/libref/Int64.html You should really use google as well...

piokuc
  • 25,594
  • 11
  • 72
  • 102
  • it is really hard to google such L postfix. what I got from google is just that int64 page – Jackson Tale Apr 25 '13 at 14:32
  • 5
    What I did was I just copy pasted the title of your question into Google search form. The first page I got was the documentation of Int64 module. Then I adjusted the search by adding 'example' to it. – piokuc Apr 25 '13 at 14:35
  • 2
    It might also help to scan the contents and index of the OCaml manual. I went to the [contents page](http://caml.inria.fr/pub/docs/manual-ocaml/manual001.html) and searched for int64. The answer showed up instantly. – Jeffrey Scofield Apr 25 '13 at 14:46
  • 1
    I will dissent a little here by stating that I think it's fine to ask relatively easy to google questions here. Answers on stackoverflow are much easier to find (even with google) then a man page. They also come with a lot of interesting related info usually. – rgrinberg Apr 25 '13 at 15:55
  • I agree to some extent - it depends on specific case. That's why I didn't downvote the question but answered on it. – piokuc Apr 25 '13 at 15:57
5

let i = 32 will give you a value of type int and not int32.

You can obtain a int64 value by adding a L after the number as pointed out by piokuc and user1034081, But I am not sure that's what you want to do. Why do you want int64?

OCaml has an internal representation for integers that is different from other languages and it store them on 31 or 63 bits (depending on your architecture) because it needs an extra bit for the GC. I you don't have a very good reason to use int64 (i.e. you want to use C code in OCaml or OCaml code in C), use the int type.

Thomash
  • 6,339
  • 1
  • 30
  • 50
  • I am actually writing a bson encoder/decoder in ocaml, which requires int32 and int64. http://bsonspec.org/#/specification – Jackson Tale Apr 25 '13 at 14:36
4

You can specify the postfix 'L' for int64:

let i = 32L

leads to: val i : int64 = 32L

user1034081
  • 618
  • 5
  • 21