lundi 1 octobre 2018

OCaml - If then else

I want to do several things inside a if then else. I read a string and then I check it's lenght. If it's 3 it does X, if it's 4 it does Y.

I tried:

let str = read_line ()

let first_approach () =
    if String.lenght str = 3
    then let    char1 = String.get str 0
         let    char2 = String.get str 1
         let    char3 = String.get str 2
    else ()

let second_approach () =
    if String.lenght str = 3
    then let    char1 = String.get str 0
         let    char2 = String.get str 1
         let    char3 = String.get str 2
         let    char4 = String.get str 3
    else ()

I want to know how to make all things inside then work. Because I get Syntax error. Thank you in advance.

Aucun commentaire:

Enregistrer un commentaire