graph - For loops in ocaml -
i want
let switchgraph cases = let g = graph.makegraph() in let g = (graph.addnode g 1) in = 2 cases let g = (graph.addnode g i) in done g
but apparently, not possible. how else can achieve this.
there 2 things need fix:
- you need use references (see
ref
,:=
,!
) this, sincelet
bindings immutable - to sequence 2 expressions, need use
;
something should work:
let switchgraph cases = let g = ref (graph.makegraph()) in g := graph.addnode (!g) 1; = 2 cases g := graph.addnode (!g) done; !g
note g
reference, , !g
value.
Comments
Post a Comment