[elm-discuss] Re: view function to call other view function with different Msg type

2017-04-22 Thread Erik Lott
view : Model -> Html Msg
view model =
div []
(model.items
  |> List.map itemView 
  |> List.map (Html.Attributes.map ItemMsg)
)




On Saturday, April 22, 2017 at 5:25:41 PM UTC-4, Vardhan wrote:
>
> [ Pardon if this appear twice ]
>
> hi,
>   this is my  toy 1st elm app.
>i'm trying to keep the 'item' of the list as a seperet module.
>
> so i have in module Item:
> -
> type alias ItemModel= { ... }
> type ItemMsg = .. | .. | ..
> itemView : ItemModel -> Html ItemMsg
> -
>
> And in the top level App  module:
> -
> type alias Model = { items: List ItemModel }
> type Msg = ItemMsg ItemMsg | ...
> view : Model -> Html Msg
> view model =
> div []
> (List.map itemView model.items )
> --
>
> Well, the problem is itemView can't be used , as it is 'Html ItemMsg', and 
> not 'Html Msg'
> However, the Item module doesn't have access to 'Msg' ( which is top level 
> ),
>
> How should I use itemView in the view function ?
>
> -Regards
> Vardhan
>
>
>

-- 
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] Why `let`?

2017-04-22 Thread Witold Szczerba
I would agree with Noah Hall, the let/in keywords make parsing easier. In a
simple expression like you provided:
a = 5
b = 6
a + b
it's all clear, but in real code things are much more complicated and
confusing. I have looked at the Todo.elm you prepared and (for me) it is
much harder to reason about.

Regards,
Witold Szczerba

On Sat, Apr 22, 2017 at 10:23 PM, Noah Hall  wrote:

> Two notes:
>
> Let bindings do not have order. Using them in the way suggested
> implies order. In this world, they would have to be ordered or
> confusion would reign. This is more imperative style.
>
> I've actually really disliked this in CoffeeScript/Ruby, that
> implicitly the last item in the block is the thing returned. Makes it
> a lot harder to parse mentally.
>
> -1.
>
> On Fri, Apr 14, 2017 at 10:00 PM, Akio Burns  wrote:
> > It's not clear to me why Elm uses `let`, instead of simply scoping
> > definitions to the expression below them.
> >
> >
> > With `let`:
> >
> > foo =
> > let
> > a = 1
> > b = 2
> > in
> > a + b
> >
> > Scoping definitions to the expression below them:
> >
> > foo =
> > a = 1
> > b = 2
> >
> > a + b
> >
> >
> > I understand that each function must contain a single expression. In Elm,
> > although they contain expressions, definitions are not expressions.
> >
> >
> > Visualized:
> >
> > foo =
> > 
> >
> > foo =
> > a + 2 <- EXPRESSION
> >
> > foo =
> > a = 1 <- DEFINITION SCOPED TO THE a + 2 EXPRESSION
> > a + 2
> >
> >
> > Another way to demonstrate scope is:
> >
> > let
> > a = 1
> > b = 2
> > in
> > a + b
> >
> > would become (parenthesis to demonstrate scope):
> >
> > (
> > a = 1
> > b = 2
> >
> > a + b
> > )
> >
> >
> > It seems to me that `let` and `in` are unnecessary and verbose. Put
> another
> > way, I think few people would agree that requiring a keyword before
> variable
> > assignment `set a = 1` would be a good idea. The `=` makes the intent
> > explicit. Likewise, indentation—or parenthesis—could make scopes
> explicit,
> > and `let` and `in` unnecessary.
> >
> > Some have argued that without `let`, we could not have arbitrarily nested
> > scopes. I don't have significant experience with Elm, but I would guess
> that
> > nesting `let`s today is pretty big code smell. Instead of nesting `let`s
> to
> > reuse variable names, developers should either pick more descriptive
> > variable names, or abstract into a function.
> >
> >
> > This could—of course—apply anywhere an expression is expected:
> >
> > True ->
> > x = 0
> > y = 0
> >
> > (x, y)
> > ...
> >
> >
> > @rtfeldman on the Slack pointed out that this syntax is more diff
> friendly:
> >
> > if I write a view function like
> > view model =
> > div []
> > [ ... lots of other stuff ]
> >
> > and then I want to introduce a nested constant like so:
> > view model =
> > let
> > foo = ...
> > in
> > div []
> > [ ... lots of other stuff ]
> >
> > the fact that I indented the final expression makes the VCS diff explode
> > this happens to me all the time, and it's pretty annoying
> > with [this] idea it wouldn't happen anymore
> >
> >
> > Lastly, here's elm-todomvc with scoped definitions, courtesy of
> @rtfeldman
> > again:
> >
> > https://github.com/rtfeldman/elm-todomvc/blob/
> 8678c8bcaeb5cb4b3f87dbefb7a01b5fe492dbc7/Todo.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.
>
> --
> 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: Elm-reactor and static files (images & videos)

2017-04-22 Thread Fernando Martinez
Hello again! 

I kept investigating and found a possible fix. I just created a Pull 
Request here:

https://github.com/elm-lang/elm-reactor/pull/228

Do let me know if I'm missing anything regarding contributions guidelines 
or anything like that, don't want to start contributing here overriding 
workflows and community ceremonies :P

Thanks very much!
Fernando

-- 
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: Elm-reactor and static files (images & videos)

2017-04-22 Thread Fernando Martinez
Hello again! 

I kept investigating and found a possible fix. I just created a Pull 
Request here:

https://github.com/elm-lang/elm-reactor/pull/228

Do let me know if I'm missing anything regarding contributions guidelines 
or anything like that, don't want to start contributing here overriding 
workflows and community ceremonies :P

Thanks very much!
Fernando


 

El sábado, 22 de abril de 2017, 19:33:29 (UTC-3), Fernando Martinez 
escribió:
>
> Hello All! 
>   I'm new to Elm and trying to build a small 
> "playlist/carousel app"  (basically, a list of videos and images that 
> passes one after the other) to learn elm and try some ideas about ports. 
>
> I think I'm having a newie problem but I could not found a solution or 
> leads to a solution (or I couldn't undestand them :P), so I'm writing here.
>
> I'm using the elm-reactor to develop and like very much the debbugger and 
> the automatic building.
>
> So, my first question is:  is it posible to serve static files (images and 
> videos) from the elm-reactor?
> (From what I could observe, it returns an empty response. perhaps I'm 
> missing something?)
>
> As a work around, I tried using a common http server to serve the app and 
> was able to have hotreloading using a file system watching library to 
> automatically build and reload the browser. But I lost the debugger :(
>
> So, the second question, depending on how the first one goes. is: is there 
> any way to open the debugger outside of elm-reactor?
>
>
> Thanks you very much!
> Fernando.
>

-- 
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] Elm-reactor and static files (images & videos)

2017-04-22 Thread Fernando Martinez
Hello All! 
  I'm new to Elm and trying to build a small "playlist/carousel 
app"  (basically, a list of videos and images that passes one after the 
other) to learn elm and try some ideas about ports. 

I think I'm having a newie problem but I could not found a solution or 
leads to a solution (or I couldn't undestand them :P), so I'm writing here.

I'm using the elm-reactor to develop and like very much the debbugger and 
the automatic building.

So, my first question is:  is it posible to serve static files (images and 
videos) from the elm-reactor?
(From what I could observe, it returns an empty response. perhaps I'm 
missing something?)

As a work around, I tried using a common http server to serve the app and 
was able to have hotreloading using a file system watching library to 
automatically build and reload the browser. But I lost the debugger :(

So, the second question, depending on how the first one goes. is: is there 
any way to open the debugger outside of elm-reactor?


Thanks you very much!
Fernando.

-- 
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] Unexpected error when parsing what seems to be reasonable code (Bug in parser maybe?)

2017-04-22 Thread Dwayne Crooks
Hi,

The following snippet of code:

view : Model -> Html Msg
> view model =
> let
> ratingViewConfig =
> { Rating.defaultViewConfig | readOnly = model.readOnly }
> in
> div []
> [ Html.map SetRatingState <|
> Rating.view ratingViewConfig model.ratingState
> , label []
> [ input
> [ type_ "checkbox"
> , checked model.readOnly
> , onClick ToggleReadOnly
> ]
> []
> , text "read only"
> ]
> ]


causes the following error to occur:

I ran into something unexpected when parsing your code!
> 63| { Rating.defaultViewConfig | readOnly = model.readOnly }
>   ^
> I am looking for one of the following things:
> a closing bracket '}'
> a lower case name
> whitespace


However, if I update the let bindings as follows:

let
> defaultViewConfig = Rating.defaultViewConfig
> ratingViewConfig =
> { defaultViewConfig | readOnly = model.readOnly }
> in
> ...


Then, there is no error. Am I missing something or is this a bug in the 
parser?

-- 
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] view function to call other view function with different Msg type

2017-04-22 Thread Vardhan
[ Pardon if this appear twice ]

hi,
  this is my  toy 1st elm app.
   i'm trying to keep the 'item' of the list as a seperet module.

so i have in module Item:
-
type alias ItemModel= { ... }
type ItemMsg = .. | .. | ..
itemView : ItemModel -> Html ItemMsg
-

And in the top level App  module:
-
type alias Model = { items: List ItemModel }
type Msg = ItemMsg ItemMsg | ...
view : Model -> Html Msg
view model =
div []
(List.map itemView model.items )
--

Well, the problem is itemView can't be used , as it is 'Html ItemMsg', and 
not 'Html Msg'
However, the Item module doesn't have access to 'Msg' ( which is top level 
),

How should I use itemView in the view function ?

-Regards
Vardhan


-- 
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] Looking for a better way to use `andThen` chains (and other beginner questions)

2017-04-22 Thread Stefan Matthias Aust
Hi there!

Just for fun, I started to learn Elm. I wonder how to idiomatically solve 
the following problems.

I decided to create a little 4X strategy game. Currently, I'm tinkering 
with the best representation of such a game and how to implement game 
commands that update the model. 

Here's a simplified run down: The game has stars and players. Each star has 
planets. Planets have properties like size, population, industry, defense, 
etc. Planets can be owned by players. Spaceships (organized as fleets (aka 
taskforces aka tfs) can move between stars. They belong to players. One 
kind of ship is the transport and it can be used to colonize unoccupied 
planets.

I refer stars, planets, players and fleets by number (aka `no`) because 
(this is my current understanding) I have no other way to refer to records 
and I need a way for the user to enter commands (I intent to eventually 
create a retro text mode interface). So a command looks like `BuildDefense 
TeamNo StarNo PlanetNo Amount` or `LandTransports TeamNo TfNo StarNo 
PlanetNo Amount`. All that types are aliases for `Int`.

This is an excerpt from type definitions:

Game = { stars : List Star, teams : List Team }
Star = { no: StarNo, planets : List Planet }
Planet = { no : PlanetNo, defense : Int }
Command = BuildDefense ... | LandTransports ...

*My first question*: Is there any way to create a constrained type like 
"something that has a `no` field?

Right now, I have a lot of nearly identical code like this:

findStar : StarNo -> Game -> Maybe Star
findStar no game =
List.head (List.filter (\star -> star.no == no) game.stars)

findPlanet : PlanetNo -> Star -> Maybe Planet
findPlanet no star =
List.head (List.filter (\planet -> planet.no == no) star.planets)

In other languages, I could create some kind of protocol or interface or 
category and then declare `Star` or `Planet` to be conforming. Then I could 
implement common operations for conforming types.

I also didn't find some kind of "find first" operation in the standard 
library (which is frankly surprisingly small). It's easy enough to 
implement but why do I need to?

find : (a -> Bool) -> List a -> Maybe a
find test list =
case list of
head :: tail ->
if test (head) then
Just head
else
find test tail

other ->
Nothing

Because I like terse code, I used the much more compact although less 
efficient variant.

Also, mainly for esthetic reasons, I'd prefer to extend the `List` module 
so that my function reads `List.find` because if I have to use `List.map` 
and `Maybe.map` and `Result.map` and `Random.map` everywhere, I'd stay 
consistent.

Sidenote, would be using `<|` more idiomatic?

findPlanet no star =
List.head <| List.filter (\planet -> planet.no == no) star.planets

*Second question*: Is there an easy way to replace an element in a list?

As I have to recreate the whole game if I change something, I crafted a lot 
of helper function:

planet
|> addDefense amount
|> subtractResources amount * defenseCost
|> updatePlanetInStar star
|> updateStarInGame game
|> Ok

This ready nicely.

The `updatePlanetInStar` and `updateStarInGame` functions are however very 
verbose:

updatePlanetInStar : Star -> Planet -> Star
updatePlanetInStar star planet =
{ star
| planets =
List.map
(\p ->
if p.no == planet.no then
planet
else
p
)
star.planets
}

Again, I'm unable to abstract it further.

Sidenote: I'd love to use 

{ game | stars[x].planets[y] = planet }

and let the compiler deal with all that stupid boilerplate code. I realize 
that for this to work, I'd have to use `Array` (a rather unsupported type) 
instead of `List` but that would be fine. That way, I could alias my `no` 
to indices. By the way, do I really had to create my own `nth` function for 
Lists?

*Third question*. When implementing `BuildDefense`, I need to convert the 
no's to records and this could fail. Instead of working with `Maybe`, I use 
a `Result Error a` type and `Error` is a sum type that contains all the 
errors that could occur. However, I get some really ugly chaining…

buildDefense : TeamNo -> StarNo -> PlanetNo -> Int -> Game -> Result Error 
Game
buildDefense teamNo starNo planetNo amount game =
findTeamR teamNo game
|> Result.andThen
(\team ->
findStarR starNo game
|> Result.andThen
(\star ->
findPlanetR planetNo star
|> Result.andThen
(\planet ->
if amount < 1 then
Err InvalidAmount
else if planet.owner /= 

Re: [elm-discuss] Why `let`?

2017-04-22 Thread Noah Hall
Two notes:

Let bindings do not have order. Using them in the way suggested
implies order. In this world, they would have to be ordered or
confusion would reign. This is more imperative style.

I've actually really disliked this in CoffeeScript/Ruby, that
implicitly the last item in the block is the thing returned. Makes it
a lot harder to parse mentally.

-1.

On Fri, Apr 14, 2017 at 10:00 PM, Akio Burns  wrote:
> It's not clear to me why Elm uses `let`, instead of simply scoping
> definitions to the expression below them.
>
>
> With `let`:
>
> foo =
> let
> a = 1
> b = 2
> in
> a + b
>
> Scoping definitions to the expression below them:
>
> foo =
> a = 1
> b = 2
>
> a + b
>
>
> I understand that each function must contain a single expression. In Elm,
> although they contain expressions, definitions are not expressions.
>
>
> Visualized:
>
> foo =
> 
>
> foo =
> a + 2 <- EXPRESSION
>
> foo =
> a = 1 <- DEFINITION SCOPED TO THE a + 2 EXPRESSION
> a + 2
>
>
> Another way to demonstrate scope is:
>
> let
> a = 1
> b = 2
> in
> a + b
>
> would become (parenthesis to demonstrate scope):
>
> (
> a = 1
> b = 2
>
> a + b
> )
>
>
> It seems to me that `let` and `in` are unnecessary and verbose. Put another
> way, I think few people would agree that requiring a keyword before variable
> assignment `set a = 1` would be a good idea. The `=` makes the intent
> explicit. Likewise, indentation—or parenthesis—could make scopes explicit,
> and `let` and `in` unnecessary.
>
> Some have argued that without `let`, we could not have arbitrarily nested
> scopes. I don't have significant experience with Elm, but I would guess that
> nesting `let`s today is pretty big code smell. Instead of nesting `let`s to
> reuse variable names, developers should either pick more descriptive
> variable names, or abstract into a function.
>
>
> This could—of course—apply anywhere an expression is expected:
>
> True ->
> x = 0
> y = 0
>
> (x, y)
> ...
>
>
> @rtfeldman on the Slack pointed out that this syntax is more diff friendly:
>
> if I write a view function like
> view model =
> div []
> [ ... lots of other stuff ]
>
> and then I want to introduce a nested constant like so:
> view model =
> let
> foo = ...
> in
> div []
> [ ... lots of other stuff ]
>
> the fact that I indented the final expression makes the VCS diff explode
> this happens to me all the time, and it's pretty annoying
> with [this] idea it wouldn't happen anymore
>
>
> Lastly, here's elm-todomvc with scoped definitions, courtesy of @rtfeldman
> again:
>
> https://github.com/rtfeldman/elm-todomvc/blob/8678c8bcaeb5cb4b3f87dbefb7a01b5fe492dbc7/Todo.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.

-- 
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] Unexpected parse error for reasonable code (Bug in parser?)

2017-04-22 Thread Dustin Farris
This is because the syntax for record updates does not allow you to update 
nested records like what you are attempting.

This is part of an ongoing discussion.  There is a thread where you can post 
your specific scenario: 
https://groups.google.com/forum/#!searchin/elm-discuss/record%7Csort:relevance/elm-discuss/oWfARte8DJU/6eUvmL-jAwAJ
 


Dustin


> On Apr 21, 2017, at 5:33 PM, Dwayne Crooks  wrote:
> 
> Hi,
> 
> I got the following syntax error:
> 
> I ran into something unexpected when parsing your code!
> 62| { Rating.defaultViewConfig | readOnly = model.readOnly }
>   ^
> I am looking for one of the following things:
> a closing bracket '}'
> a lower case name
> whitespace
> 
> for the following snippet of code:
> 
> view : Model -> Html Msg
> view model =
> let
> ratingViewConfig =
> { Rating.defaultViewConfig | readOnly = model.readOnly }
> in
> div []
> [ Html.map SetRatingState <|
> Rating.view ratingViewConfig model.ratingState
> , label []
> [ input
> [ type_ "checkbox"
> , checked model.readOnly
> , onClick ToggleReadOnly
> ]
> []
> , text "read only"
> ]
> ]
> 
> If however I write the following:
> 
> let
> defaultViewConfig = Rating.defaultViewConfig
> ratingViewConfig =
> { defaultViewConfig | readOnly = model.readOnly }
> in 
> ...
> 
> Then everything works fine. Is this a bug in the parser?
> 
> -- 
> 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 
> .

-- 
Dustin Farris



-- 
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] updating records syntax

2017-04-22 Thread Dustin Farris
There is ongoing discussion around this.  You might consider posting your 
specific scenario here: 
https://groups.google.com/forum/#!searchin/elm-discuss/record%7Csort:relevance/elm-discuss/oWfARte8DJU/6eUvmL-jAwAJ
 


Dustin

> On Apr 20, 2017, at 5:34 AM, Samuel Walladge  wrote:
> 
> I'm new to elm, and was experimenting with updating records today. Noticed 
> something that seemed a bit strange - the elm compiler doesn't accept 
> updating a record where you specify the record you want to update with `{ 
> myRecord.myNestedRecord | ... }` (syntax error).
> 
> I've attached an example file displaying this behaviour. `example5` and 
> `example6` don't compile. What I'm wondering is, should they compile based on 
> the elm language specification? And, for example 5, when you want to update a 
> nested record, is that nested syntax a good way to go about it, or is there a 
> neater way?
> 
> For reference, this is the error I get when compiling:
> 
> -- SYNTAX PROBLEM - 
> Test.elm
> 
> I ran into something unexpected when parsing your code!
> 
> 24| example6 = { myRecord.user | name = "John" }
>  ^
> I am looking for one of the following things:
> 
>  "'"
>  "|"
>  an equals sign '='
>  more letters in this name
>  whitespace
> 
> Detected errors in 1 module.
> 
> 
> Thanks.
> 
> 
> -- 
> 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 
> .
> 

-- 
Dustin Farris



-- 
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] Unexpected parse error for reasonable code (Bug in parser?)

2017-04-22 Thread Dwayne Crooks
Hi,

I got the following syntax error:

I ran into something unexpected when parsing your code!
> 62| { Rating.defaultViewConfig | readOnly = model.readOnly }
>   ^
> I am looking for one of the following things:
> a closing bracket '}'
> a lower case name
> whitespace


for the following snippet of code:

view : Model -> Html Msg
> view model =
> let
> ratingViewConfig =
> { Rating.defaultViewConfig | readOnly = model.readOnly }
> in
> div []
> [ Html.map SetRatingState <|
> Rating.view ratingViewConfig model.ratingState
> , label []
> [ input
> [ type_ "checkbox"
> , checked model.readOnly
> , onClick ToggleReadOnly
> ]
> []
> , text "read only"
> ]
> ]


If however I write the following:

let
> defaultViewConfig = Rating.defaultViewConfig
> ratingViewConfig =
> { defaultViewConfig | readOnly = model.readOnly }
> in 

...


Then everything works fine. Is this a bug in the parser?

-- 
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] Optimisation in Elm

2017-04-22 Thread Ana Borovac
Hi,

I have some theoretical questions:

- why is Elm so fast? is there some kind of tail-recursion behind or is 
this just the part that JavaScript does?
- how is the storage mastered (garbage collection)?
- does commands (Cmd) influence on pureness of Elm?

Thank you so much for your help!

Ana

-- 
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: Discovery: Model /= Database

2017-04-22 Thread Dustin Farris
Interesting approach to just cache things in local storage and use the 
Model as a view "state" only.

I keep a nice store in my Model, but I think a key difference is that I'm 
using websockets to update information automatically.  Each route (page) 
has a list of channels that it cares about, and when data comes in on those 
channels, the store is updated.

WRT your issue on authenticated routes, my approach was to write a function 
that checks the model for a Maybe String which is the JWT token.  If it was 
Nothing, I'd send a Cmd to navigate to the login page.  It has worked well 
so far.


On Wednesday, April 19, 2017 at 7:28:06 PM UTC-4, Kasey Speakman wrote:
>
> I'm probably slow, but in recent months I've discovered that trying to use 
> Elm's Model like a database or cache (as I have previously seen suggested) 
> has turned out to be pretty painful for me. An example database-minded 
> model where a section could display *either* a list of employees *or* a 
> list of courses.
>
> type alias Model =
> { employees : List Employee
> , courses : List Course
> , loadingError : Maybe Http.Error
> , route : MyRoute -- employee or course
> }
>
> The problem this runs into is having to worry about state management. I 
> have to remember to "reset" or "turn off" things when they are not active. 
> As my application grew, I had a lot of problems that boiled down to tedious 
> state management details. My cached data didn't turn out to be all that 
> useful because I usually had to reload it anyway, in case something changed.
>
> Instead, I have been moving toward the model only representing the current 
> state of my UI. The big difference here is the model representing the 
> current *visual* elements and their data. This leads more to using union 
> types to represent parts of the UI. When you switch to a different case of 
> the union type, the data from the previous case is *dropped on the floor*. 
> This leaves nothing to remember to "reset". RemoteData is a good 
> micro-example of this. If there was an error fetching the data, when the 
> user requests the data again, you switch back to Loading, the error message 
> is dropped on the floor. No forgetting to hide it.
>
> type RemoteData e a
> = NotAsked
> | Loading
> | Failure e
> | Success a
>
> If it is really important to cache the data, I prefer to keep that as a 
> persistence concern, not on Model. It can be part of the process for 
> retrieving the data to first check my chosen cache before making a request 
> for fresh data. For instance, first check local storage before making an 
> HTTP call. (Currently, this scenario is easier with Native modules for lack 
> of Local Storage API or being able to wait on port subscriptions. But it's 
> still doable.)
>
> So working towards a Model reflecting the visuals on the page has been an 
> interesting challenge. I'm not claiming it's easier, but so far I've found 
> it avoids a class of problems, and has led to some interesting discoveries 
> in my own apps. One small example: I realized that my LoggedIn and 
> NotLoggedIn routes should actually be separate "apps". Attempts to model 
> this in a SPA fashion with the LoggedIn and NotLoggedIn routes as siblings 
> always came up with the conundrum: how do I make it a compiler error for 
> the model to be in LoggedIn mode but I receive a NotLoggedIn message, or 
> vice versa? Even using TEA, I could not avoid this situation. Then I 
> realized the only way to do that would be as separate apps. And that it was 
> entirely possible to separate them. My "login page" turned out to be an 
> entirely self-contained process: the user filling in info, obtaining a 
> token, and saving it to local storage.
>
> I post this in the slim hope it is helpful to someone.
>

-- 
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] Charty: SVG charts library (feedback request)

2017-04-22 Thread Juan Edi
Hello everyone,

Today I released a library to generate SVG markup for charts.

It certainly worked for my particular use case but I'd love to hear if it
works for you or if I'm missing something.
There is still work to do regarding API design and features, but I thought
I'd better release soon and get some feedback from all of you.

Docs: http://package.elm-lang.org/packages/juanedi/charty/latest
Repo: https://github.com/juanedi/charty
Demo: https://juanedi.github.io/charty/

Thanks!

-- 
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] updating records syntax

2017-04-22 Thread Samuel Walladge
I'm new to elm, and was experimenting with updating records today. Noticed 
something that seemed a bit strange - the elm compiler doesn't accept 
updating a record where you specify the record you want to update with `{ 
myRecord.myNestedRecord | ... }` (syntax error).

I've attached an example file displaying this behaviour. `example5` and 
`example6` don't compile. What I'm wondering is, should they compile based 
on the elm language specification? And, for example 5, when you want to 
update a nested record, is that nested syntax a good way to go about it, or 
is there a neater way?

For reference, this is the error I get when compiling:

>
> -- SYNTAX PROBLEM - 
> Test.elm
>
> I ran into something unexpected when parsing your code!
>
> 24| example6 = { myRecord.user | name = "John" }
>  ^
> I am looking for one of the following things:
>
>  "'"
>  "|"
>  an equals sign '='
>  more letters in this name
>  whitespace
>
> Detected errors in 1 module.



Thanks.

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


Test.elm
Description: Binary data


[elm-discuss] Why `let`?

2017-04-22 Thread Akio Burns
It's not clear to me why Elm uses `let`, instead of simply scoping 
definitions to the expression below them.


With `let`:

foo =
let
a = 1
b = 2
in
a + b

Scoping definitions to the expression below them:

foo =
a = 1
b = 2

a + b


I understand that each function must contain a single expression. In Elm, 
although they contain expressions, definitions are not expressions.


Visualized:

foo =


foo =
a + 2 <- EXPRESSION

foo =
a = 1 <- DEFINITION SCOPED TO THE a + 2 EXPRESSION
a + 2


Another way to demonstrate scope is:

let
a = 1
b = 2
in
a + b

would become (parenthesis to demonstrate scope):

(
a = 1
b = 2

a + b
)


It seems to me that `let` and `in` are unnecessary and verbose. Put another 
way, I think few people would agree that requiring a keyword before 
variable assignment `set a = 1` would be a good idea. The `=` makes the 
intent explicit. Likewise, indentation—or parenthesis—could make scopes 
explicit, and `let` and `in` unnecessary.

Some have argued that without `let`, we could not have arbitrarily nested 
scopes. I don't have significant experience with Elm, but I would guess 
that nesting `let`s today is pretty big code smell. Instead of nesting 
`let`s to reuse variable names, developers should either pick more 
descriptive variable names, or abstract into a function.


This could—of course—apply anywhere an expression is expected:

True ->
x = 0
y = 0

(x, y)
...


@rtfeldman on the Slack pointed out that this syntax is more diff friendly:

if I write a view function like
view model =
div []
[ ... lots of other stuff ]

and then I want to introduce a nested constant like so:
view model =
let
foo = ...
in
div []
[ ... lots of other stuff ]

the fact that I indented the final expression makes the VCS diff explode
this happens to me all the time, and it's pretty annoying
with [this] idea it wouldn't happen anymore


Lastly, here's elm-todomvc with scoped definitions, courtesy of @rtfeldman 
again:

https://github.com/rtfeldman/elm-todomvc/blob/8678c8bcaeb5cb4b3f87dbefb7a01b5fe492dbc7/Todo.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: Structuring model and messages | Debouncing in a large app

2017-04-22 Thread Gusztáv Szikszai
I've never though about using an effect manager for debouncing, it makes 
much more sense. Thanks for sharing!

On Saturday, April 22, 2017 at 9:25:03 AM UTC+2, Gusztáv Szikszai wrote:
>
> This is really good :+1
>
> On Thursday, April 20, 2017 at 10:00:50 PM UTC+2, jsch...@pivotal.io 
> wrote:
>>
>> My comment is RE debouncing in particular.  I too have been frustrated to 
>> see so many debouncing libraries.  The problem is that none of them are 
>> great, because debouncing makes the most sense to solve as a managed 
>> effect, rather than in user-space.  And, effect packages can't be published 
>> afaik.  There are quite a few of this type out there on github.  The one 
>> that we use to good effect is here: 
>> https://github.com/tracker-common/elm-debouncer/blob/be3bd02ccac6b71b0088c08359b3f45b5ae7c4dc/src/Debouncer.elm
>>  
>> (sorry for the outstanding PR).  It provides an api very similar to 
>> Task.attempt, but the task given to it will be debounced.  There are 
>> similar ones that deal with Msg instead of tasks (
>> https://github.com/unbounce/elm-debounce), but I like to keep my effects 
>> in tasks as long as possible so I can chain/map them as needed before 
>> sending them out.
>>
>> On Thursday, April 20, 2017 at 3:18:28 AM UTC-6, Simon wrote:
>>>
>>> First of all - 6 debouncing libraries! Would be great to see elm-package 
>>> be able to surface github stars directly (or some other means of identify 
>>> the most-likely-to-be-good library)
>>>
>>> My question though is the following. The type signature of a debounce 
>>> state is DebounceState Msg. I.e. it needs the message type as that’s 
>>> what it is going to send back later.
>>>
>>> But in a large app, I usually have the model in 1 file and import that 
>>> into my update/view files and it is in the latter that I define the type 
>>> Msg.
>>>
>>> I’m quickly going to get a singularity if I try to import my Msgs into 
>>> my model.
>>>
>>> I’ve never separated out my Msgs before into a separate file but can 
>>> see some other benefits. But there will also be costs too.
>>>
>>> So I was wondering 
>>>
>>>- what other experiences people had had with separating out Msgs 
>>>- whether there was an alternative to this to handle the issue at 
>>>hand - debouncing (all of the examples in the libraries are tiny single 
>>>file ones inevitably) 
>>>
>>> ​
>>>
>>

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