Re: [elm-discuss] Re: How do you handle dependencies between updaters?

2017-03-20 Thread Oliver Searle-Barnes
Mark that sounds interesting, I take it you have an equivalent of Cmd.map? 

-- 
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] Re: Task ports: A proposal to make it easier to integrate JS with Elm.

2017-03-20 Thread Mark Hamburg
Agreed.

Tasks actually were the core way to do things in 0.16 — though ports then
were more focused on reactive programming models as I recall. Effects (what
essentially became commands) were largely a shim on top of tasks. But then
along came Elm 0.17 and it's emphasis on effects managers accessed via
commands and subscriptions and we started to see less functionality
delivered via tasks. But it feels like effects managers have stalled out —
e.g., Evan's local storage effects manager, documentation, etc — leaving
few clear answers here.

Ports are interesting but as noted don't really scale well for any cases
where you need to send in messages and get back matched responses —
particularly if those responses need to result in different messages to the
app.

So, is there a reason for why Elm doesn't place more emphasis on tasks and
provide something like task ports as a way to leverage JavaScript
functionality?

Mark

On Thu, Mar 9, 2017 at 6:47 PM, Jeff Schomay  wrote:

> Just want to add my desires for this functionality and bump this topic.
>
> My current need is to add a new `li` item to a `ul`, find its offsetTop
> and scroll to it (so that the top of the new item is at the top of the
> window).  I can't find a more "Elm-y" way of doing this besides hitting a
> port to get the offsetTop and then use Dom.Scroll.toY to get there (maybe
> with some animation).  It would be great to chain all of that in a series
> of tasks, but currently I have to make a new message for the port and
> respond to that with my scroll code :-/.
>
> In general, after using Elm a lot over the many months, I'm learning that
> the monadic properties of Tasks (ie. chaining with `andThen`) are extremely
> powerful and expressive and composable, not to mention easier to test with
> libraries like arborist.  I'm just sad that there aren't more api's that
> return Tasks.
>
>
>
> On Saturday, August 13, 2016 at 9:31:07 AM UTC-6, James Wilson wrote:
>>
>> The problem
>>
>> ports as they stand are fundamentally incompatible with Tasks. Being
>> backed by Cmd's, they are harder to compose. A frustration of mine is that
>> often we are directed to "just use ports" when a proper interface to some
>> native API is not yet available, but this leads to our Msg types growing
>> and more significant changes being required when eventually the proper
>> interface is made available.
>>
>> Also, many JS interop things I find myself wanting to do are
>> fundamentally one-shot functions which I expect a result back into Elm from
>> immediately, or otherwise just want to compose with other Task based
>> things. Some examples that come to mind of one-shot tasks you may want to
>> compose rather than use the streaming interface that ports provide:
>>
>>- Getting items from local/sessionStorage
>>- .. really, most things involving working with the Web API that
>>arent yet implemented in Elm.
>>- Embedding JS widgets into Elm elements
>>- Using a JS library for doing things like hashing passwords or
>>obtaining some data back from some custom service
>>- Interacting with things like Electron for creating apps that can
>>run in the desktop and interact with the filesystem etc.
>>
>>
>> The solution
>>
>> Task ports. The idea is that these are defined the same way that Ports in
>> elm currently are, but they return a Task type rather than a Cmd or Sub
>> type. On the JS Side, we attach a function to the Elm app that returns a
>> Promise, and on the Elm side we wait for the Promise returned to reject or
>> resolve, and marhsall the error or result from the promise into the error
>> or result type required by the Task type of the port.
>>
>> Let's see how this might work:
>>
>>
>> *Ports.elm:*
>>
>> port apiSession: Task String SessionId
>>
>>
>>
>> *Main.elm:*
>>
>> import Ports
>> import Json.Decode as Decode
>> import Task exposing (andThen)
>>
>>
>> -- get an API session from JS land and make an http request using it
>> -- given some path and a decoder to decipher the result:
>> apiRequest : String -> Decoder a -> Task ApiError a
>> apiRequest path decoder =
>>   let
>> headers sessId =
>> [ ("Content-Type", "application/json")
>> , ("MyApp-SessionId", sessId)
>> ]
>>
>>
>> req sessId = Http.send Http.defaultSettings
>> { verb = "POST"
>> , headers = headers sessId
>> , url = path
>> }
>>
>>
>> decodeResponse res = Decode.decodeString decoder -- ...handle error
>> etc
>>   in
>> Ports.apiSession `andThen` req `andThen` decodeResponse
>>
>>
>> *App.js:*
>>
>> Elm.Main.ports.apiSession = function(){
>> return new Promise(function(resolve,reject){
>>
>>
>> var sess = localStorage.getItem("sessionId");
>> if(!sess) reject("NO_SESSION");
>> else resolve(sess);
>>
>>
>> });
>> }
>>
>> var app = Elm.Main.fullscreen();
>>
>>
>>
>>
>> Here, we use a tiny bit of JS to access localStorage and pull out a
>> session ID. This function 

Re: [elm-discuss] Re: How do you handle dependencies between updaters?

2017-03-20 Thread Mark Hamburg
Our application essentially replaces `Cmd Msg` in `update : Msg -> Model ->
( Model, Cmd Msg )` with the notion of an "out message" in the form `update
: Msg -> Model -> ( Model, List OutMsg )`. Like a command, an out message
is a request for action beyond the scope of the model being updated.
Commands are just a specialization of this notion that flows out the top of
the program (and over to the effects managers). In fact, one standard entry
in the out message union types is `Command (Cmd Msg)`. The update pattern
for submodels consists in running their update functions, storing the
update submodel into the containing model, and then processing the out
messages to perform further updates at the level of the containing model or
to produce out messages that will pass further up the tree. An example of
such an out message is `DidLogin AuthToken` which allows the sign in logic
to report up to the rest of the app that we've successfully signed in and
obtained an auth token. Fancy usage actually allows for running up the
hierarchy to obtain some non-local piece of information before continuing
an update but I'm not sure I'm really fond of that approach as an
alternative to just passing and translating more out messages.

Mark

On Mon, Mar 20, 2017 at 1:51 PM, Martin Norbäck Olivers 
wrote:

> And it helps to not think about the functions "interacting" with each
> other. They don't. A function can call another function. Nothing is
> stopping you from calling the content update function or the user update
> function from another update function, but I find it helps to just factor
> out the common functionality into separate functions that can be called
> from multiple places.
>
> And if you have an update function that needs to update several
> "sub-models", just pass all the sub-models and get the updated sub-models
> back. Or pass the main model and let it update the parts it needs to update.
>
>
>> The challenge is when there are dependencies between Updaters, for
>>> example the User Profile model might need data from the Session model, the
>>> Session updater might need to send messages to the User updater (Load user
>>> profile when session is updated), or the Content updater may need to check
>>> for the Session updater (get session ID to send as parameter to the API
>>> when fetching content), or some business-specific updater may need to
>>> interact with both the Content updater, the User updater, and the
>>> Configuration updater.
>>>
>>> In Redux, one would use combineReducers to mount each reducer under its
>>> own path, and then one can trigger actions across reducers. How would you
>>> solve this in Elm?
>>>
>>
>> I find it helps to think not about sending messages to somebody but
>> returning a command. If the session updater needs to load a user profile,
>> it returns a command do to that and you map that onto the user message
>> type. If the user profile needs data from the session model, you pass that
>> data to the view function.
>>
>> It only gets hard when you try to think of them as separate components.
>> They're not, they are just a collection of functions.
>>
> --
> 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.


[elm-discuss] Re: How do you handle dependencies between updaters?

2017-03-20 Thread Martin Norbäck Olivers
And it helps to not think about the functions "interacting" with each 
other. They don't. A function can call another function. Nothing is 
stopping you from calling the content update function or the user update 
function from another update function, but I find it helps to just factor 
out the common functionality into separate functions that can be called 
from multiple places.

And if you have an update function that needs to update several 
"sub-models", just pass all the sub-models and get the updated sub-models 
back. Or pass the main model and let it update the parts it needs to update.


> The challenge is when there are dependencies between Updaters, for example 
>> the User Profile model might need data from the Session model, the Session 
>> updater might need to send messages to the User updater (Load user profile 
>> when session is updated), or the Content updater may need to check for the 
>> Session updater (get session ID to send as parameter to the API when 
>> fetching content), or some business-specific updater may need to interact 
>> with both the Content updater, the User updater, and the Configuration 
>> updater.
>>
>> In Redux, one would use combineReducers to mount each reducer under its 
>> own path, and then one can trigger actions across reducers. How would you 
>> solve this in Elm?
>>
>
> I find it helps to think not about sending messages to somebody but 
> returning a command. If the session updater needs to load a user profile, 
> it returns a command do to that and you map that onto the user message 
> type. If the user profile needs data from the session model, you pass that 
> data to the view function.
>
> It only gets hard when you try to think of them as separate components. 
> They're not, they are just a collection of functions. 
>

-- 
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.


[elm-discuss] Re: How do you handle dependencies between updaters?

2017-03-20 Thread Martin Norbäck Olivers


> The challenge is when there are dependencies between Updaters, for example 
> the User Profile model might need data from the Session model, the Session 
> updater might need to send messages to the User updater (Load user profile 
> when session is updated), or the Content updater may need to check for the 
> Session updater (get session ID to send as parameter to the API when 
> fetching content), or some business-specific updater may need to interact 
> with both the Content updater, the User updater, and the Configuration 
> updater.
>
> In Redux, one would use combineReducers to mount each reducer under its 
> own path, and then one can trigger actions across reducers. How would you 
> solve this in Elm?
>

I find it helps to think not about sending messages to somebody but 
returning a command. If the session updater needs to load a user profile, 
it returns a command do to that and you map that onto the user message 
type. If the user profile needs data from the session model, you pass that 
data to the view function.

It only gets hard when you try to think of them as separate components. 
They're not, they are just a collection of functions. 

-- 
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] Re: Is it possible to create a circular reference in Elm?

2017-03-20 Thread Martin Norbäck Olivers


> The reason I was thinking about it was not actually anything to do with 
> garbage collection. I have a data modelling language with a type system, 
> but it has grown in a slightly ad-hoc manner and needs some 
> rationalization. I was wondering how well the type alias records + tagged 
> unions + basic types part of Elm would suit my purposes. As the data models 
> I build are often mapped onto relational database or mutable objects, I do 
> need circular references to be possible.
>

I don't see the rationale for requiring circular references to map onto a 
relational database though, they are referenced by key, not by pointer.
Mutable objects can of course use circular references, and some algorithms 
depend heavily on them, but they are a pain to handle for instance when 
serializing. Which you do a lot in a web app.

-- 
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] Fwd: Us congress hearing of maan alsaan Money laundry قضية الكونغجرس لغسيل الأموال للمليادير معن الصانع

2017-03-20 Thread Chad Woolley
FYI, this spammer made it through the new moderate-first-post settings
because we had forgotten to delete the membership, but there was already a
prior post by the member.  Membership is now deleted.  Shouldn't happen
again unless there's other already-posted sleeper spammers lurking in the
members list.

-- Chad

2017-03-18 8:45 GMT-07:00 sam a :

>
>
>
>
>
>
> *موقع اليوتيوب الذي عرض فيديوهات جلسة استماع الكونجرس الأمريكي *
>
> * لمتابعة نشاطات غسل الأموال ونشاطات*
>
>
>
> *السعودي معن عبدالواحد الصانع*
>
> *مالك مستشفى  وشركة سعد  ومدارس سعد بالمنطقة الشرقية** بالسعودية * * ورئيس
> مجلس ادارة بنك اوال البحريني*
>
>
>
>  *وتعليق محطة سي ان بي سي التلفزيونية*
>
>
>
> *مترجم باللغة العربية*
>
>
>
> US Congressional Hearing of
>
>  Saudi billionaire" maan  Al Sanea "
>
>  and Money Laundering
>
> with bank of America
>
>
>
> With Arabic Subtitles
>
>
>
>
>
> http://www.youtube.com/watch?v=mIBNnQvhU8s
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> --
> 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.


Re: [elm-discuss] Re: Post Examples of Painful Record Updates Here!

2017-03-20 Thread Max Goldstein
@art, I disagree about adding arbitrary expressions between { and |. You 
should use a let-binding for something like *Array.get (offset + i) 
arrayOfRecords |> Maybe.withDefault defaultRecord*.

I know this is supposed to be pain points, not solutions, I'm going to try 
to coalesce some of the syntax proposals that have been brought up.

*Qualified names as base records*, such as {Module.defaultOptions | ... }. 
The default options pattern makes this very useful and it does not 
encourage nesting records deeply.

*Dot-accessed records as base records*. This would allow { element.padding 
| left = "4px" }. Having records as fields of other records is especially 
useful when the subrecord type can be reused (e.g. { padding : Rect, margin 
: Rect }.

*Arbitrary expressions as base records*. Allow anything of record type. I 
disagree with this one per above.

-

*Nested getter functions*, so that *.foo.bar* is sugar for *.foo >> .bar*

*Setter functions*, perhaps with syntax *.foo=*

*Nested setter functions*, a combination of the two above, *.foo.bar=*

*Setters that take a function given the current value of the field as an 
argument.* *padding |> .right@ (\padRight -> padRight * 2)* This is 
particularly useful for mapping over lists instead of setting one value.

*-*

I wonder if we could dispense with the vertical bar update syntax entirely 
if we had nested setters. Something like

Style.defaults
  |> .padding.left = 5
  |> .margin.top = 10

The compiler should specifically optimize this case so that many chained 
updates do not create intermediate records. (A downside is that you lose 
the ability to refer to the current record in the expression for the new 
value, but that record wouldn't exist because of the optimization. So that 
would mean you can't easily map over a list that's in a record.)

-- 
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.


[elm-discuss] Re: How do you handle dependencies between updaters?

2017-03-20 Thread Dmitry Utkin
I've came up with solution very similar to Oliver's :)

Top `Page`(or `Screen`) update functions are getting the `Store` which is a 
top level app model. Alternative way is to have `mapToContext` function 
that receives some `Props` and `Store` and maps those to some useful 
context(it might be useful for both view and update functions, btw).

Each top-level `Page` update fn also returns an instance of `Action` that 
helps modifying the store.

On Monday, March 20, 2017 at 1:58:38 PM UTC+2, Eirik Sletteberg wrote:
>
> In larger Elm apps, it makes sense to divide Updaters so you can 
> package-by-feature.
> For example, a single page application could have updaters like this:
>
> - Configuration updater
> - Session updater
> - User Profile updater
> - User Settings updater
> - Content updater
> - Some other business specific updater
>
> The challenge is when there are dependencies between Updaters, for example 
> the User Profile model might need data from the Session model, the Session 
> updater might need to send messages to the User updater (Load user profile 
> when session is updated), or the Content updater may need to check for the 
> Session updater (get session ID to send as parameter to the API when 
> fetching content), or some business-specific updater may need to interact 
> with both the Content updater, the User updater, and the Configuration 
> updater.
>
> In Redux, one would use combineReducers to mount each reducer under its 
> own path, and then one can trigger actions across reducers. How would you 
> solve this in Elm?
>
>

-- 
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.


[elm-discuss] Re: How do you handle dependencies between updaters?

2017-03-20 Thread Oliver Searle-Barnes
My current approach has two parts:

1) A Context record which is passed to all update functions
2) A pseudo Cmd called AppCmd which is returned from the updates as (model, 
cmd, appCmd)

The Context includes shared information like Session and Store (where I 
keep data records), any modifications that should be made to that shared 
information are requested as an AppCmd. e.g.

AppCmd.storeMsg (Store.addUser user)

At the top level those AppCmds are then dispatched appropriately to other 
updates. I haven't gone as far as returning information back to the 
original caller (i.e. the equivalent of Msg with Cmds) but so far I haven't 
found any need to. 


On Monday, 20 March 2017 12:58:38 UTC+1, Eirik Sletteberg wrote:
>
> In larger Elm apps, it makes sense to divide Updaters so you can 
> package-by-feature.
> For example, a single page application could have updaters like this:
>
> - Configuration updater
> - Session updater
> - User Profile updater
> - User Settings updater
> - Content updater
> - Some other business specific updater
>
> The challenge is when there are dependencies between Updaters, for example 
> the User Profile model might need data from the Session model, the Session 
> updater might need to send messages to the User updater (Load user profile 
> when session is updated), or the Content updater may need to check for the 
> Session updater (get session ID to send as parameter to the API when 
> fetching content), or some business-specific updater may need to interact 
> with both the Content updater, the User updater, and the Configuration 
> updater.
>
> In Redux, one would use combineReducers to mount each reducer under its 
> own path, and then one can trigger actions across reducers. How would you 
> solve this in Elm?
>
>

-- 
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.


[elm-discuss] How do you handle dependencies between updaters?

2017-03-20 Thread Eirik Sletteberg
In larger Elm apps, it makes sense to divide Updaters so you can 
package-by-feature.
For example, a single page application could have updaters like this:

- Configuration updater
- Session updater
- User Profile updater
- User Settings updater
- Content updater
- Some other business specific updater

The challenge is when there are dependencies between Updaters, for example 
the User Profile model might need data from the Session model, the Session 
updater might need to send messages to the User updater (Load user profile 
when session is updated), or the Content updater may need to check for the 
Session updater (get session ID to send as parameter to the API when 
fetching content), or some business-specific updater may need to interact 
with both the Content updater, the User updater, and the Configuration 
updater.

In Redux, one would use combineReducers to mount each reducer under its own 
path, and then one can trigger actions across reducers. How would you solve 
this in Elm?

-- 
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.


[elm-discuss] Fwd: Us congress hearing of maan alsaan Money laundry قضية الكونغجرس لغسيل الأموال للمليادير معن الصانع

2017-03-20 Thread sam a
*موقع اليوتيوب الذي عرض فيديوهات جلسة استماع الكونجرس الأمريكي *

* لمتابعة نشاطات غسل الأموال ونشاطات*



*السعودي معن عبدالواحد الصانع*

*مالك مستشفى  وشركة سعد  ومدارس سعد بالمنطقة الشرقية** بالسعودية * * ورئيس
مجلس ادارة بنك اوال البحريني*



 *وتعليق محطة سي ان بي سي التلفزيونية*



*مترجم باللغة العربية*



US Congressional Hearing of

 Saudi billionaire" maan  Al Sanea "

 and Money Laundering

with bank of America



With Arabic Subtitles





http://www.youtube.com/watch?v=mIBNnQvhU8s

-- 
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] Re: Is it possible to create a circular reference in Elm?

2017-03-20 Thread 'Rupert Smith' via Elm Discuss
On Saturday, March 18, 2017 at 5:24:16 PM UTC, Mark Hamburg wrote:
>
> I've been thinking about this as well because functional languages should 
> provide a great basis for exploiting multi core systems.
>

The reason I was thinking about it was not actually anything to do with 
garbage collection. I have a data modelling language with a type system, 
but it has grown in a slightly ad-hoc manner and needs some 
rationalization. I was wondering how well the type alias records + tagged 
unions + basic types part of Elm would suit my purposes. As the data models 
I build are often mapped onto relational database or mutable objects, I do 
need circular references to be possible.

-- 
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.