Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to structure Libraries in Elm?

Tags:

elm

I am in the process of tidying up some Elm code and I was wondering how to do the following:

Suppose I have the following File Structure

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

|...

Suppose that I have divided up the BMW and Mercedes code into different files in order to keep my code small and seperate and so it's much easier for me to just 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 having to write

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

Ideally, I'd like to just write something like

import Car (..)

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

Is it possible? If so, what is the best strategy to do so?

like image 503
TheSeamau5 Avatar asked Dec 06 '14 18:12

TheSeamau5


1 Answers

Elm doesn't support re-exporting modules so it isn't possible to create a single module which exports a handful of others which you can use to qualify functions. Assuming that you have distinct function names, you could 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 won't be able to get the fully qualified name to export from the Utils module.

Hope this helps!

like image 126
Joe Avatar answered Oct 28 '22 03:10

Joe