ocamlutop

Return Changed value of Parameter in OCAML


let rule1 m = 
    m = m/2;
    m

rule1(250) should return 125 but instead returns 250.

How is it possible to return an updated value of a parameter?


Solution

  • Are you sure m is mutable? The m = .. statement will not update the provided argument. Would returning the updated value be an option?

    let rule1 m = 
        m/2