I was wondering if there is a way for type members to refer to each other. I would like to write the following program as follows:
type IDieRoller = abstract RollDn : int -> int abstract RollD6 : int abstract RollD66 : int type DieRoller() = let randomizer = new Random() interface IDieRoller with member this.RollDn max = randomizer.Next(max) member this.RollD6 = randomizer.Next(6) member this.RollD66 = (RollD6 * 10) + RollD6
But, this.RollD66 cannot see this.RollD6. I can understand why, but it seems that most functional languages have a way to tell functions that they exist ahead of time so that this or similar syntax is possible.
Instead, I had to do the following, which is not much more code, but it seems that the former would look more elegant than the latter, especially if there are more such cases.
type DieRoller() = let randomizer = new Random() let rollD6 = randomizer.Next(6) interface IDieRoller with member this.RollDn max = randomizer.Next(max) member this.RollD6 = rollD6 member this.RollD66 = (rollD6 * 10) + rollD6
Any tips? Thanks!
source share