Name: Anonymous 2008-05-07 21:51
fuck me im soo stoopid
Here is the function that is messing with me due to my inadequate understanding.
let generateTicket =
let count = ref 0
(fun () -> count := !count + 1; !count)
Okay in the above code, the first thing that happens is that it declares a local element of state called count. Then it returns a function value that refers to this state. Every call it increments and dereferences this state.
No my question is how do I actually get at the dereferenced count (!count).
Logically I would think something like
printfn "%d" generateTicket
would work since it returns an Integer. For some reason it says incompatible type (unit -> int)
so of course if this is a function that takes nothing and creates an integer at least going
let x = generateTicket
should return an int since I don't use x() etc
but even when I do this I can't get at the derefenced count...
How the fuck do I get at it?
Here is the function that is messing with me due to my inadequate understanding.
let generateTicket =
let count = ref 0
(fun () -> count := !count + 1; !count)
Okay in the above code, the first thing that happens is that it declares a local element of state called count. Then it returns a function value that refers to this state. Every call it increments and dereferences this state.
No my question is how do I actually get at the dereferenced count (!count).
Logically I would think something like
printfn "%d" generateTicket
would work since it returns an Integer. For some reason it says incompatible type (unit -> int)
so of course if this is a function that takes nothing and creates an integer at least going
let x = generateTicket
should return an int since I don't use x() etc
but even when I do this I can't get at the derefenced count...
How the fuck do I get at it?