Search code examples
castingocaml

OCaml: Converting / casting bool to int


How do you cast an ocaml boolean to an integer? (There's no int_of_bool function.)


Solution

  • Here's one possible implementation:

    let int_of_bool b = if b then 1 else 0
    

    The library OCaml Batteries Included has a function to_int in its BatBool module.