Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regarding F# Object Oriented Programming

Tags:

oop

f#

There's this dichotomy in the way we can create classes in f# which really bothers me. I can create classes using either an implicit format or an explicit one. But some of the features that I want are only available for use with the implicit format and some are only available for use with the explicit format.

For example:

  1. I can't use let inline* (or let alone) inside an explicitly defined class.

  2. The only way (that I know) to define immutable public fields (not properties*) inside an implicitly defined class is the val bla : bla syntax.

    But there's a redundancy here. Since I'll end up with two copy of the same immutable data, one private, one public (because in the implicit mode the constructor parameters persist throughout the class existence)

  3. (Not so relevant) The need to use attributes for method overloading and for field's defaults is rather off putting.

Is there anyway I can work around this?

*For performance reasons

EDIT: Turns out I'm wrong about both points (Thanks Ganesh Sittampalam & MichaelGG).

  1. While I can't use let inline in both implicit & explicit class definition, I can use member inline just fine, which I assume does the same thing.

  2. Apparently with the latest F# there's no longer any redundancy since any parameters not used in the class body are local to the constructor.

  3. Will be gone in the next F# release.

like image 435
Dave Berk Avatar asked Jul 31 '09 13:07

Dave Berk


1 Answers

This might not help, but you can make members inline. "member inline private" works fine.

like image 127
MichaelGG Avatar answered Nov 09 '22 04:11

MichaelGG