3

I am looking for functional equivalence for the following C# code:

public virtual ICollection<Dog> Dogs { get; set; }

I have been up and down SO and MSDN, to no avail. Is there a different construct for properties other than this:

let mutable dogID = 0

member public self.DogID
    with get() = dogID
    and set(value) = dogID <- value
ildjarn
  • 62,044
  • 9
  • 127
  • 211
Jamie Dixon
  • 4,204
  • 4
  • 25
  • 47

2 Answers2

3

You can use auto properties:

member val Dogs = List<Dog>() with get,set 
7sharp9
  • 2,147
  • 16
  • 27
2

OK, Apparently I need to SO (the verb) even better. I found this this which led me to this:

let mutable dogs = List<DOG>() :> ICollection<DOG> 


member public self.Dogs
    with get() = dogs
    and set(value) = dogs <- value      

Thanks to Dave for pointing me at the explicit class. Also, Genesh, I think that is what your question was? Thanks for helping also.

Community
  • 1
  • 1
Jamie Dixon
  • 4,204
  • 4
  • 25
  • 47
  • 3
    That's not going to make the property `virtual`, if that's important to you. The documentation explains how to do that: http://msdn.microsoft.com/en-us/library/dd483467.aspx – Mark Seemann Aug 10 '14 at 20:23
  • You didn't ask but I'd also strongly consider whether or not that collection needs to be mutable. Mutable is a code smell in functional programming--not necessarily wrong but something to really think about. You're more likely to want to create a new object if you need to associate a different dog collection with it. – Onorio Catenacci Aug 12 '14 at 21:19
  • I am mapping back to an interfaces that was defined in C#. LOL, the collection is from Entity Frameworks – Jamie Dixon Aug 12 '14 at 23:25