3 ms·
F# could potentially get a module system in the future (a la OCaml or SML). I've put together some proof-of-concept code to show how modules could be implemente
by profquail 13y ago
F# could potentially get a module system in the future (a la OCaml or SML). I've put together some proof-of-concept code to show how modules could be implemented on top of the existing .NET type system, so at this point it's just a matter of refining that representation and then implementing that in the language/compiler.
- Hakeashar 13y agoI'd love to see some kind of typeclass support in F#... In the meantime, honest question: what are modules in OCaml? I tried to read up on it online, but my understanding of the topic is still murky. Regular modules don't really seem that interesting (they look like modules and/or types/classes in F#), parametrized modules seem to be something that is missing in F#. Second question, do you have that proof of concept code laying somewhere around? I'm just curious how it would look in F#...
- profquail 13y agoYes, F# is missing parameterized modules ("functors"); these are simply modules which are parameterized by other modules in the same way .NET generics (for example) allow you to parameterize one type by another type. The reason this would be nice to have in F# is that, while the CLR's generics are excellent in general, there are some things that can't be expressed using the CLR's type constraints. Supporting functors in F# would provide a nice way to work around this and allow you to write code which is more generic. Here's my proof-of-concept code. I'll warn you now though -- it looks quite messy, because the goal was to show that functors could be supported on top of the existing .NET type system. If functors are ever added to the F# language, the syntax will be much, much cleaner. https://github.com/jack-pappas/experimental-functors https://github.com/jack-pappas/experimental-functors
- sixbrx 13y agoThis is great news (thank you for doing it)! Especially that it doesn't require changes within the CLR which seems to be a death sentence for proposals. I've been teetering with trying F#, and a proper ML-like module system may tip the balance in its favor for me, I'm sure I'm not alone in that. It just didn't seem like a "real" ML without the module system or at least type classes.