Re: [elm-discuss] Unrelated modules having ports with the same name

2016-08-31 Thread James Wilson
There is as I understand it nothing wrong with compiling multiple modules with 
a main function using one command. It's very useful if you want many separate 
Elm widgtts that share the same runtime and library code. As I understand you 
can do:


Foo.hs:

module Foo
main = HTML.App.Program...

Bar.hs:

module Bar
main = HTML.App.Program...

elm-make Foo.elm Bar.elm --output combined.JS

And combined.JS will expose Elm.Foo and Elm.Bar, which can separately be 
instantiated but share the same runtime and things.

All of this to say, I would assume that ports should be scoped by the main 
module that imports them and that this is a bug.

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Unrelated modules having ports with the same name

2016-08-30 Thread b123400
Thanks for the reply.

I want to try out Elm as embedded element(s) instead of full page app, but 
due to the original DOM structure and CSS layout, I cannot put everything 
inside a single element. Then I thought it would be a good idea to create 
two separated modules, and "pipe" then through ports. I think this should 
be allowed?

Nick H於 2016年8月23日星期二 UTC+8下午10時54分07秒寫道:
>
> This is the intended behavior. The strange thing about what you are trying 
> to do is that ModuleA and ModuleB both have a function called main. Are you 
> intending them to be a part of the same program? Programs should only have 
> one "main" function.
>
> If ModuleA and ModuleB are supposed to be different programs, then you 
> should not be compiling them in the same elm-make command. I am kind of 
> surprised that the compiler lets you do this.
>
>
>
>
> On Mon, Aug 22, 2016 at 10:25 AM, b123400 > 
> wrote:
>
>> Hello, I find it confusing about ports in modules, I have sent an issue 
>>  but didn't get 
>> notice for a month, so I'd like to post it here for discussion.
>>
>> I have two modules, they both have a port with the same name:
>>
>> port module ModuleA exposing (main)
>> import Html exposing (text)import Platform.Sub as Sub
>> port incomePort : (String -> msg) -> Sub msg
>> main =
>>   text "Hello"
>>
>> port module ModuleB exposing (main)
>> import Html exposing (text)import Platform.Sub as Sub
>> port incomePort : (String -> msg) -> Sub msg
>> main =
>>   text "Hey!"
>>
>> And I compiled it by this command:
>>
>> elm make ModuleA.elm ModuleB.elm --output combined.js
>>
>> The generated JS file will output the following error:
>>
>> Error: There can only be one port named `incomePort`, but your program has 
>> multiple.
>>
>> These two modules are not connected and there should be no ambiguity 
>> between the ports. I think the ports name checking should be bounded to the 
>> module, instead of JS-file-wise.
>>
>> By the way, when I generate the modules separately and include them in 
>> the same page, there is no error.
>>
>> elm make ModuleA.elm --output a.js
>> elm make ModuleB.elm --output b.js
>>
>> 
>> 
>>
>> Is this behaviour intended?
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Elm Discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to elm-discuss...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Unrelated modules having ports with the same name

2016-08-23 Thread Nick H
This is the intended behavior. The strange thing about what you are trying
to do is that ModuleA and ModuleB both have a function called main. Are you
intending them to be a part of the same program? Programs should only have
one "main" function.

If ModuleA and ModuleB are supposed to be different programs, then you
should not be compiling them in the same elm-make command. I am kind of
surprised that the compiler lets you do this.




On Mon, Aug 22, 2016 at 10:25 AM, b123400  wrote:

> Hello, I find it confusing about ports in modules, I have sent an issue
>  but didn't get
> notice for a month, so I'd like to post it here for discussion.
>
> I have two modules, they both have a port with the same name:
>
> port module ModuleA exposing (main)
> import Html exposing (text)import Platform.Sub as Sub
> port incomePort : (String -> msg) -> Sub msg
> main =
>   text "Hello"
>
> port module ModuleB exposing (main)
> import Html exposing (text)import Platform.Sub as Sub
> port incomePort : (String -> msg) -> Sub msg
> main =
>   text "Hey!"
>
> And I compiled it by this command:
>
> elm make ModuleA.elm ModuleB.elm --output combined.js
>
> The generated JS file will output the following error:
>
> Error: There can only be one port named `incomePort`, but your program has 
> multiple.
>
> These two modules are not connected and there should be no ambiguity
> between the ports. I think the ports name checking should be bounded to the
> module, instead of JS-file-wise.
>
> By the way, when I generate the modules separately and include them in the
> same page, there is no error.
>
> elm make ModuleA.elm --output a.js
> elm make ModuleB.elm --output b.js
>
> 
> 
>
> Is this behaviour intended?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Elm Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to elm-discuss+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.