4 ms·
f# definitely allows this with single case discriminated unions. and in f#, you can add members to any type, which includes discriminated unions, records, class
by nikofeyn 8y ago
f# definitely allows this with single case discriminated unions. and in f#, you can add members to any type, which includes discriminated unions, records, classes, etc.
in fact, you can add member functions somewhere else after the definition of the type. so you can define the type, write functional helper functions against that type and then later add member functions to the type that are defined in terms of the helper functions.
- vram22 8y agoDidn't know that stuff, cool, thanks. (In early stage of learning F#). That feature you mention sounds a bit like Ruby's open classes, where, in file B (or even in file A), you can add a method to a class C (where C is defined in file A), outside of the definition of C. I was just reading somewhere else recently that some other language also has this feature, maybe it was about Lisp, in the recent thread about it.