hubFS: THE place for F#

. . . are you on The Hub?
Welcome to hubFS: THE place for F# Sign in | Join | Help
in Search

Data encapsulation and static members in F#

Last post 07-07-2006, 15:03 by dsyme. 1 replies.
Sort Posts: Previous Next
  •  07-07-2006, 9:31 414

    Data encapsulation and static members in F#

    A few questions about F#.

    1) I am not sure whether or not it is possible to hide certain fields or members in F# e.g. using private and protected keywords.

    2) Is it possible to have a static field in a class? Even in a non object oriented framework, this is useful in a number of cases. e.g. storing the previous seed in a random number generator, unique id generator. In an object oriented framework, this could be used to implement the Singleton pattern. If not, is there a standard way to implement using the FP approach.

    I appreciate your thoughts on the matter. Thanks in advance.

    Regards

    Chris
  •  07-07-2006, 15:03 415 in reply to 414

    Re: Data encapsulation and static members in F#

    Hi Chris,

    You should use signatures to hide things.  See http://research.microsoft.com/fsharp/manual/quicktour.aspx#QuickTourSignatures and the several examples of signatures in the *.fsi and *.mli files in the samples in the distribution.

    Signatures are great for functional programming, or when the interface to a module is thin, but can be a bit less satisfying for metadata-rich OO programming, where you can end up with lots of duplication between implementation and signature.  We're currently looking into modifying the signature mechanism, partly through a "private" keyword, and partly by allowing signature declarations ("module types") inline in implementation files.

    Cheers!

    Don

     

View as RSS news feed in XML
Powered by Community Server, by Telligent Systems