Well I figured out the problem. I was due to the circular dependency I fixed it by making my Synapse class generic like so:

type 'a Synapse(n1 : 'a, n2 : 'a, weight : float) =
member v.Weight = weight
member v.Left = n1
member v.Right = n2

But I'm still wondering, Does F# have anything to handle circular dependency problems like this I guess I could create an interface but is that my only option?

By on 8/12/2008 1:33 PM ()

Hi Burntchips,

for mutually dependent classes you can use the 'and' keyword.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
type Neuron(fireLevel, fireStrength) =
    let mutable _axions : Synapse list = []
    let mutable _dendrites : Synapse list = []
    member v.FireLevel = fireLevel
    member v.FireStrength = fireStrength
    member v.Axions with get() = _axions
    member v.Dendrites with get() = _dendrites
    member v.ConnectFrom(source : Synapse) =
        _axions <- source :: _axions
    member v.ConnectTo(target : Neuron, weight : float) =
        let syn = Synapse(v, target, weight)
        _dendrites <- syn :: _dendrites
        target.ConnectFrom syn
    new() = Neuron(1.0f, 1.0f)
   
and Synapse(n1 : Neuron, n2 : Neuron, weight : float) =
    member v.Weight = weight
    member v.Left = n1
    member v.Right = n2

hope that helps.

regards,

Danny

By on 8/12/2008 3:02 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper