7

I'm imagining a situation where you are creating an F# module in a purely functional style. This means objects do not have mutable fields and are not modified in place. I'm assuming for simplicity that there is no need to use .NET objects or other kinds of objects. There are two possible ways of implementing an object-oriented kind of solution: the first is to use classes and the second to use records which have fields of functional type, to implement methods.

I imagine you'd use classes when you want to use inheritance but that otherwise records would be adequate, if perhaps clumsier to express. Or do you find classes more convenient than records in any case?

svick
  • 10,049
fairflow
  • 173
  • 6

1 Answers1

3

MSDN recommends that you use value types for immutable types with "single-value" semantics that have a footprint of 16 bytes or less. This should give you some guidelines to decide.

CesarGon
  • 2,981
  • Thanks CesarGon that's useful. However the project I'm working on is using records that are rather larger than that! Are we sure that F# records are actually implemented as value types? They can also have methods attached, which seems surprising in this context. Heap space is a serious limitation for us as well. – fairflow Feb 18 '13 at 16:44
  • 4
    @fairflow: According to this http://stackoverflow.com/questions/5858550/f-records-vs-net-struct, F# records are actually reference types, so I guess value types are of no use to you here. – CesarGon Feb 18 '13 at 21:39