module exposing syntax #1951
amitu
started this conversation in
Ideas & RFCs
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
If a module
foo
(defined infoo.ftd
) wants to create an internal module, sayinternal
, to keep things organised, eg it needs a bunch of private functions and components, and want to only expose some stuff frominternal
module, it can do this:Content of
foo.ftd
:At this point, people can import
foo
and accessfoo.x
, sincex
is exposed.foo.internal.x
is the place it is defined, and that should be also be accessible, unlessinternal
is markedprivate
. Or we go with private by default, and require-- public module internal:
.Why Are We Considering This?
This is actually a "hack", a solution to the problem: do we have a syntax to define a function inside a function, as that brings us to
f-script
callingp-script
, and we want to say no, we are saying if you want to define a new function, you have to continue to usep-script
function definition syntax. But what if that function needs internal functions, or needs closures etc. We are saying, don't define them inline, and give them names and put them all in a "module", and just expose the real thing you want to expose using exposing syntax.Anonymous closures, I can see value of, and I want, if we can figure out how to do type check the whole thing, currently every variable etc has to have type, we do not have type inference.
But defining full blown named functions inside other functions, things that Rust / JavaScript / Python etc also, I am not fan of, they are solution for a problem, "these functions are only related to this function and internal to it etc", so they say let me define them inside the function itself, but I am saying module is better abstraction, this gives you more breathing space, less indentation needed etc, and just fewer concept (no function inside function inside function, but you can argue we are saying yes for module inside module inside module, but module is much better thing, why just function inside function inside function, why Rust, why not struct inside function inside struct, etc etc.
Beta Was this translation helpful? Give feedback.
All reactions