Re: [elm-discuss] Re: Exporting an event stream

2016-08-16 Thread Kasey Speakman
I watched a video on the debugger, and it seems possible to ignore the 
commands with some native javascript modifying Elm's behavior. Seems messy 
though.

On Tuesday, August 16, 2016 at 11:35:33 PM UTC-5, Zachary Kessin wrote:
>
> By Side effects I meant commands, sorry still have not had any tea yet 
> today 
>
> Zach
> ᐧ
>
> On Wed, Aug 17, 2016 at 7:34 AM, Zachary Kessin  > wrote:
>
>> I think the format for exporting types must be someform of json encoding, 
>> for everyone's sanity. And I think when you are in "Re play mode" side 
>> effects should be ignored in favor of the existing events.
>>
>> Zach
>> ᐧ
>>
>> On Tue, Aug 16, 2016 at 7:35 PM, Kasey Speakman > > wrote:
>>
>>> I've started looking at this. The first hurdle is that updates return 
>>> both a model update and a side effect. So you could not replay side effects 
>>> as they may not be deterministic. (Replay produces Cmd which returns a 
>>> different result message from first time. The time traveling debugger gets 
>>> around this by disabling Cmd when replaying.) Not to mention running Cmds 
>>> depends on some outside access (at least mocking it).
>>>
>>> There is a discussion of that here 
>>>  and I 
>>> made a gist of a possible way to implement side effect isolation here 
>>> . 
>>> Look at the comment first to see what it looks like in use.
>>>
>>> The other hurdle is events are likely to be union types with data. All 
>>> the JSON encoding/decoding I've see in Elm for union types are for the 
>>> simple kind where the case has no other values (like an enum). So having a 
>>> case with values will be a challenge. In JSON.NET, serialized F# union 
>>> type `CaseName ("something", 1, 3.5)` would look like this: `{ "Case": 
>>> "CaseName", "Fields": ["something", 1, 3.5] }`. Note: case values are 
>>> tuples in F#. Javascript allows arrays to contain dissimilar types, so this 
>>> works.
>>>
>>> But, making a custom encoder/decoder for every union case makes you want 
>>> to rethink life choices. Indeed, it might be better to just use Redux-style 
>>> messages where the type is a string so you can send the events out of a 
>>> port for free. It's a shame to lose out on that nice union syntax, but man 
>>> the pain.
>>>
>>> Even then, you will still feel the pain on decoding. Actually, decoding 
>>> anything is painfully manual in Elm. However, there are no surprises that 
>>> way.
>>>
>>> On Thursday, July 28, 2016 at 6:58:58 AM UTC-5, Zachary Kessin wrote:

 I know the idea of having an event stream that can be exported and 
 replayed has been kicked around a bit for a while. Has anyone ever done 
 anything with this? 

 Ideally I would like to be able to generate a sequence of events with a 
 QuickCheck type tool (either in elm or erlang)

 Zach

 -- 
 Zach Kessin
 SquareTarget 
 Twitter: @zkessin 
 Skype: zachkessin
 ᐧ

>>> -- 
>>> 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.
>>>
>>
>>
>>
>> -- 
>> Zach Kessin
>> SquareTarget 
>> Twitter: @zkessin 
>> Skype: zachkessin
>>
>
>
>
> -- 
> Zach Kessin
> SquareTarget 
> Twitter: @zkessin 
> Skype: zachkessin
>

-- 
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: Child model change propagation problem in elm architecture

2016-08-16 Thread Magnus Rundberget
Hi, 

I would suggest reading through this thread, in particular the answers 
provided by Richard.
https://groups.google.com/forum/#!topic/elm-discuss/_cfOu88oCx4

my tldr in your case: Seriously consider whether you really need to 
separate things as components vs just separating out functions and keeping 
your model flatter.
(your calculate functions should not take in a nested model imho, that's a 
sure way to make it brittle !) 

-magnus



On Wednesday, 17 August 2016 04:51:15 UTC+2, Jacky See wrote:
>
>
> Hi, I'm a new comer to elm. I try to build application using elm and have 
> some problem on component.
>
> Suppose I'm building an BMI calculator, initially I have a model
>
> type alias Model = { weight:Int, height:Int }
>
> The rendering is just an two input[type=number].
> The result is rendered by a pure function at the main app:
>
> calclulate model = 
>   let 
> h = (toFloat model.height) / 100
> w = toFloat model.weight
>   in
> toString (round (w / (h*h)))
>
>
> One day a decision made to change those two inputs into a component of its 
> own (BmiConfig). 
> So the models become
>
> --at main app 
> type alias Model = { bmiConfig: BmiConfig.Model ... }
>
> --at BmiConfig
> type alias Model = {weight:Int, height:Int}
>
> We need to to the work of connecting Msg, etc. The calculate function 
> becomes
>
> calclulate model = 
>   let 
> h = (toFloat model.config.height) / 100
> w = toFloat model.config.weight
>   in
> toString (round (w / (h*h)))
>
>
> Another a change comes and requesting add +/- button to the number input. 
> We try to make a small generic component NumberInput. Models become:
>
> --at main app 
> type alias Model = { bmiConfig: BmiConfig.Model ... }
>
> --at BmiConfig
> type alias Model = {weight:NumberInput.Model, height:NumberInput.Model}
> 
> --at NumberInput
>  type alias Model = {value:Int, max:Int, min:Int,  }
>
> The calculate function needs to be changed again:
>
> calculate model =
>   let 
> h = (toFloat model.config.height.value) / 100
> w = toFloat model.config.weight.value
>   in
> toString (round (w / (h*h)))
>
> It seems to me that every refactoring to extract component would lead to a 
> propagation
> of change all the ways from child to its parents. Parents need to know the 
> data
> structure of child to do calculation too. Is that the correct way of 
> applying the elm architecture?
> Have I missed something?
>  
>
>
>
>

-- 
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] text editor for Elm + GLSL

2016-08-16 Thread Nick H
The list has been talking about text editors lately. For those of you who
use elm-webgl, is there a text editor that can properly format GLSL code
blocks?

fragmentShader : Shader {} Uniform Varying
> fragmentShader =
> [glsl|
>  precision mediump float;
>  varying vec4 fragColor;
>
>  void main () {
>  gl_FragColor = fragColor;
>  }
> |]
>

I am an Emacs user. As has been mentioned before, Emacs elm-mode
indentation is busted. This isn't a problem for me most of the time, thanks
to elm-format. But elm-format does not touch GLSL blocks, so I'm stuck
fixing the indentation by hand.

Any suggestions? Thanks!

~Nick

-- 
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: Possible bug in Html

2016-08-16 Thread Simon
On Slack i was advised to use Html.Keyed and that fixed it
Thanks so much
Simon

On Tuesday, 16 August 2016 18:50:15 UTC+2, Wouter In t Velt wrote:
>
> My guess would be that this behavior is caused by changing from 3 to 2 
> options while doing the first selection.
>
> Chrome Inspector doesn't even show me the "selected" attribute.
> But with a static list of 3 items it works as expected 
> (change your view function to below to see)
> view model =
>   select
> [ onInput Switch ] <|
>[ option [ value "1"
> , selected <| model == Just "1"
> ] [ text "one" ]
>, option [ value "2"
> , selected <| model == Just "2"
> ] [ text "two" ]
>, option [ value "3"
> , selected <| model == Just "3"
> ] [ text "three" ]
>]
>
>
> My gut feel is that the virtual DOM diff engine is messing things up: on 
> the second render, elm knows you now have 2 instead of 3 options, but elm 
> does NOT know which of the original option has gone.
> You may want to check out Html.keyed, which is introduced specifically to 
> tackle this. 
> http://package.elm-lang.org/packages/elm-lang/html/1.1.0/Html-Keyed
>
> I copied the refactored code (with keyed) below. not sure if it solves 
> your issue though.
> Unfortunately, Elm-try does not recognize Html.keyed (yet).
> module Test exposing (..)
>
> import Html exposing (..)
> import Html.Keyed as Keyed
> import Html.App as App
> import Html.Attributes exposing (..)
> import Html.Events exposing (..)
>
> import List exposing (map)
> import Json.Decode as Json
>
> type alias Model =
> Maybe String
>
> init = Nothing
>
> type Msg
> = Switch String
>
> update (Switch s) model =
> Debug.log"" <| Just s
>
> view model =
> let
> kvs =
> [ ("1", "One")
> , ("2", "Two")
> ]
> -- makeOpts now returns List (String, Html Msg) to use in Html.
> keyed
> makeOpts lst selectedKey =
> lst
> |> map (\(k, v) ->
> (k, option
> [ value k
> , selected <| k == selectedKey
> ] [ text v ])
> )
> in
>   Keyed.node "select"
> [ onInput Switch ] <|
> case model of
> Just s ->
> makeOpts kvs s
> Nothing ->
> makeOpts
> (("0", "Zero") :: kvs)
> "0"
>
> main = App.beginnerProgram
> { model = init
> , view = view
> , update = update
> }
>
>
>
>
>

-- 
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: Exporting an event stream

2016-08-16 Thread Kasey Speakman
I've started looking at this. The first hurdle is that updates return both 
a model update and a side effect. So you could not replay side effects as 
they may not be deterministic. (Replay produces Cmd which returns a 
different result message from first time. The time traveling debugger gets 
around this by disabling Cmd when replaying.) Not to mention running Cmds 
depends on some outside access (at least mocking it).

There is a discussion of that here 
 and I 
made a gist of a possible way to implement side effect isolation here 
. Look 
at the comment first to see what it looks like in use.

The other hurdle is events are likely to be union types with data. All the 
JSON encoding/decoding I've see in Elm for union types are for the simple 
kind where the case has no other values (like an enum). So having a case 
with values will be a challenge. In JSON.NET, serialized F# union type 
`CaseName ("something", 1, 3.5)` would look like this: `{ "Case": 
"CaseName", "Fields": ["something", 1, 3.5] }`. Note: case values are 
tuples in F#. Javascript allows arrays to contain dissimilar types, so this 
works.

But, making a custom encoder/decoder for every union case makes you want to 
rethink life choices. Indeed, it might be better to just use Redux-style 
messages where the type is a string so you can send the events out of a 
port for free. It's a shame to lose out on that nice union syntax, but man 
the pain.

Even then, you will still feel the pain on decoding. Actually, decoding 
anything is painfully manual in Elm. However, there are no surprises that 
way.

On Thursday, July 28, 2016 at 6:58:58 AM UTC-5, Zachary Kessin wrote:
>
> I know the idea of having an event stream that can be exported and 
> replayed has been kicked around a bit for a while. Has anyone ever done 
> anything with this? 
>
> Ideally I would like to be able to generate a sequence of events with a 
> QuickCheck type tool (either in elm or erlang)
>
> Zach
>
> -- 
> Zach Kessin
> SquareTarget 
> Twitter: @zkessin 
> Skype: zachkessin
> ᐧ
>

-- 
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-mdl implementations - suggest projects that can be added to reference list

2016-08-16 Thread Håkon Rossebø
Elm-mdl  - is getting more usage in 
various applications/projects. To improve documentation, we want to create 
a list of implementations - all kinds - simple to complex and use it as a 
reference on elm-mdl . I would 
appreciate if people could suggest any implementations that can be added to 
this list.

If you know any projects/applications/repositories - reply to this thread.

-- 
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: Design question: using Dict, List with index, or Array (or something I'm not aware of)

2016-08-16 Thread Wouter In t Velt
Touche, I had an omission in my snippet also :)
The getItem should have been:

getItem : List Item -> ID -> Maybe Item
getItem : list id =
  List.filter (\item -> item.id == id) list
  |> List.head


To turn the (maybe empty) list of with the item-to-get into a Maybe Item.

I did use a lot of Dict also for data, but in my code that frequently 
generated a lot of turning Dict into Lists (for rendering, sorting, 
filtering, counting etcetera).
But I guess it depends on typical use case.

-- 
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] Possible bug in Html

2016-08-16 Thread Simon
Would welcome some help and/or checking of this before I post as an issue. 
Try clicking on `One` and you should find yourself taken to "Two"

Simon

```
module Test exposing (..)

import Html exposing (..)
import Html.App as App
import Html.Attributes exposing (..)
import Html.Events exposing (..)

import List exposing (map)
import Json.Decode as Json

type alias Model =
Maybe String

init = Nothing

type Msg
= Switch String

update (Switch s) model =
Debug.log"" <| Just s

view model =
let
kvs =
[ ("1", "One")
, ("2", "Two")
]
makeOpts lst selectedKey =
lst
|> map (\(k, v) ->
option
[ value k
, selected <| k == selectedKey
] [ text v ])
in
select
[ onInput Switch ] <|
case model of
Just s ->
makeOpts kvs s
Nothing ->
makeOpts
(("0", "Zero") :: kvs)
"0"

main = App.beginnerProgram
{ model = init
, view = view
, update = update
}
```

-- 
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 Training class Berlin Sept 19-21

2016-08-16 Thread Zachary Kessin
Hi Everyone!

I wanted to let people know that I am going to be teaching a 3 day training
class on Elm in Berlin on September 19-21. So for folks in and around
Berlin who may have wanted to introduce elm at your company, this might be
a great way to get everyone up to speed.

You can find details At Elm Training Berlin


-- 
Zach Kessin
SquareTarget 
Twitter: @zkessin 
Skype: zachkessin
ᐧ

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