F# - When do you use a class instead of a record when you do not want to use mutable fields?

Posted by fairflow on Programmers See other posts from Programmers or by fairflow
Published on 2012-09-28T22:36:43Z Indexed on 2012/09/29 9:48 UTC
Read the original article Hit count: 120

Filed under:

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 type 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?

© Programmers or respective owner

Related posts about F#