How to structure libraries in Elm?

I'm going to remove some Elm code, and I was wondering how to do this:

Suppose I have the following file structure

Project | |---Car | |--- BMW.elm | |--- Mercedes.elm |... 

Suppose I split the BMW and Mercedes code into different files so that my code is small and separate, so it’s much easier for me to add another file, say Toyota.elm

Now I would like for any files inside the Project folder to just access all the files in the Car folder without writing

 import Car.BMW (..) import Car.Mercedes (..) ...etc... 

Ideally, I would just write something like

 import Car (..) 

and that gives me access to everything inside each of these files.

Is it possible? If so, what is the best strategy for this?

+6
source share
1 answer

Elm does not support re-export modules, so it is impossible to create a single module that exports several others that you can use to qualify functions. Assuming you have different function names, you can do something like this:

 module Utils where import Foo import Bar foo = Foo.foo bar = Bar.bar 

Then you can do

 module Other where import Utils (..) baz = foo 1 2 3 gak = bar 2 3 

But you cannot get the full name for export from the Utils module.

Hope this helps!

+1
source

Source: https://habr.com/ru/post/979227/


All Articles