Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qualified import #221

Closed
lpil opened this issue Jan 2, 2018 · 10 comments
Closed

Qualified import #221

lpil opened this issue Jan 2, 2018 · 10 comments

Comments

@lpil
Copy link
Contributor

lpil commented Jan 2, 2018

Hello!

I prefer to qualify my imported functions by default as I believe that the module name on the call makes it much clearer where functions are defined. Is there a way to import functions in a qualified way? It seems that import module.function permits both qualified and unqualified calls of the imported function.

Cheers,
Louis

@j14159
Copy link
Collaborator

j14159 commented Jan 2, 2018

Given:

mod a
export add
let add x y = x + y

Then this is OK:

mod b
import a.add
let foo () =
  -- both of these will work:
  let _ = a.add 1 1 in
  let _ = add 1 1 in
  :done

And this is OK:

mod b

let foo () =
  -- qualified only since there's no import:
  let _ = a.add 1 1 in
  :done

But this will fail to compile:

mod b

let foo () =
  -- works:
  let _ = a.add 1 1 in
  -- should fail because no import:
  let _ = add 1 1 in
  :done

Importing only works for exported functions and is a way to drop qualification, it won't expose an un-exported function from, for example, a. Does this run counter to what you're after?

@lpil
Copy link
Contributor Author

lpil commented Jan 2, 2018

Oops! Too much Haskell and Elm. I presumed some sort of import statement is always required. Thanks!

@lpil lpil closed this as completed Jan 2, 2018
@lpil
Copy link
Contributor Author

lpil commented Jan 2, 2018

Is it possible to alias a long module name? Something like alias my_app_data_user as user ?

@lpil lpil reopened this Jan 2, 2018
@j14159
Copy link
Collaborator

j14159 commented Jan 2, 2018

Not at present, no. I'm totally fine with seeing that feature added though it'd be low priority for my own personal work queue. Probably not a huge change, can probably accomplish this with a rewrite in alpaca_ast_gen.erl.

@OvermindDL1
Copy link

Is it possible to alias a long module name? Something like alias my_app_data_user as user?

OCaml's syntax for that would be much nicer:

module User = My_app_data

@lpil
Copy link
Contributor Author

lpil commented Jan 16, 2018

I didn't want to imply this would go as far as a first module system :)

@OvermindDL1
Copy link

I didn't want to imply this would go as far as a first module system :)

Aww, but the beam VM would so very well support first-class modules. ^.^

@j14159
Copy link
Collaborator

j14159 commented Jan 17, 2018

Aww, but the beam VM would so very well support first-class modules. ^.^

I'm working on a reading list for this :) (mostly because I have a lot to learn)

@OvermindDL1
Copy link

OvermindDL1 commented Jan 17, 2018

I'm working on a reading list for this :) (mostly because I have a lot to learn)

Oh if you have questions about first class modules, higher polymorphic modules, Functors, or basically anything else in OCaml, I can explain in detail. :-)

HPT's (like OCaml's Module system) is significantly more powerful than essentially all of Haskell's typing system alone as it can emulate, for example, even typeclasses (as a VERY simple example) but significantly more performant in compilation time (and with no runtime costs over standard dispatch, which even that is optimizable out with a couple simple passes). All while HPT's have a singular syntax representation unlike Haskell's type system horrors. :-)

@j14159
Copy link
Collaborator

j14159 commented Jan 17, 2018

I can explain in detail. :-)

I may yet take you up on that :) Currently I'm still intrigued by the possibilities in 1ML but need to dig in more. I'm thinking we do need something that synthesizes Erlang modules out of Alpaca sig+module combinations, it's just not at the very top of my list yet :D (algebraic effects and the FFI are other large-scale/scope things to figure out too, along the lines of discussion in #7).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants