Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
    
I didn't know F# had type classes, that's awesome! I should take another look at it. –  Jörg W Mittag Sep 29 '12 at 8:53
    
Sorry Jörg, I should have just said "classes". F# has generic classes (classes parameterised by type variables) but it does not have type classes proper. See link –  fairflow Sep 29 '12 at 9:47
3  
FWIW you can emulate typeclasses in F# : code.google.com/p/fsharp-typeclasses –  Mauricio Scheffer Sep 29 '12 at 18:24
add comment

1 Answer

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.

share|improve this answer
    
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
1  
@fairflow: According to this 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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.