Re: [elm-discuss] Re: Passing properties as arguments to messages?

2016-11-22 Thread Austin Bingham
This article really opened my eyes to the possibilities of lenses and their
interaction with the Return monad:
https://toast.al/posts/2016-10-20-optical-swordplay-with-components.html

Definitely worth a read.

On Tue, Nov 22, 2016 at 8:17 PM Nick H  wrote:

> You might look at lenses (e.g. elm-monocle) to see one approach that might
> appeal to you.
>
>
> This is pretty cool. I've often made setter functions for my records,
> wrapping around Elm's regular update syntax. I didn't realize that it's
> part of a larger class of patterns.
>
> On Tue, Nov 22, 2016 at 7:13 AM, Austin Bingham 
> wrote:
>
> You might look at lenses (e.g. elm-monocle) to see one approach that might
> appeal to you. Lenses are apparently frowned upon by some, but I think they
> capture the essence of what you're asking.
>
> On Tue, Nov 22, 2016 at 4:04 PM Wouter In t Velt 
> wrote:
>
> Op dinsdag 22 november 2016 15:55:25 UTC+1 schreef Rex van der Spuy:
>
> But, can anyone explain why Elm doesn't let us do this?
>
>
> My impression is that it has to do with the enforced strong typing and
> type safety of elm.
>
> A record is intended for key-value type info where each value could be of
> a different type.
> And elm's greatness requires that elm always knows the type it is working
> on.
> Dynamic typing for records (which javascript does allow for objects) would
> break this guarantee.
>
> So with a record, you get the flexibility that each field could be
> whatever type, but you lose the dynamicness (is that even a word?) of the
> keys.
> With Dict, it is the other way around. You can get a value by supplying a
> dynamic key, but all values in the Dict must be of the same type.
>
> --
> 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.
>

-- 
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: Passing properties as arguments to messages?

2016-11-22 Thread Nick H
>
> You might look at lenses (e.g. elm-monocle) to see one approach that might
> appeal to you.


This is pretty cool. I've often made setter functions for my records,
wrapping around Elm's regular update syntax. I didn't realize that it's
part of a larger class of patterns.

On Tue, Nov 22, 2016 at 7:13 AM, Austin Bingham 
wrote:

> You might look at lenses (e.g. elm-monocle) to see one approach that might
> appeal to you. Lenses are apparently frowned upon by some, but I think they
> capture the essence of what you're asking.
>
> On Tue, Nov 22, 2016 at 4:04 PM Wouter In t Velt 
> wrote:
>
>> Op dinsdag 22 november 2016 15:55:25 UTC+1 schreef Rex van der Spuy:
>>
>> But, can anyone explain why Elm doesn't let us do this?
>>
>>
>> My impression is that it has to do with the enforced strong typing and
>> type safety of elm.
>>
>> A record is intended for key-value type info where each value could be of
>> a different type.
>> And elm's greatness requires that elm always knows the type it is working
>> on.
>> Dynamic typing for records (which javascript does allow for objects)
>> would break this guarantee.
>>
>> So with a record, you get the flexibility that each field could be
>> whatever type, but you lose the dynamicness (is that even a word?) of the
>> keys.
>> With Dict, it is the other way around. You can get a value by supplying a
>> dynamic key, but all values in the Dict must be of the same type.
>>
>> --
>> 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.


Re: [elm-discuss] Re: Passing properties as arguments to messages?

2016-11-22 Thread Austin Bingham
You might look at lenses (e.g. elm-monocle) to see one approach that might
appeal to you. Lenses are apparently frowned upon by some, but I think they
capture the essence of what you're asking.

On Tue, Nov 22, 2016 at 4:04 PM Wouter In t Velt 
wrote:

> Op dinsdag 22 november 2016 15:55:25 UTC+1 schreef Rex van der Spuy:
>
> But, can anyone explain why Elm doesn't let us do this?
>
>
> My impression is that it has to do with the enforced strong typing and
> type safety of elm.
>
> A record is intended for key-value type info where each value could be of
> a different type.
> And elm's greatness requires that elm always knows the type it is working
> on.
> Dynamic typing for records (which javascript does allow for objects) would
> break this guarantee.
>
> So with a record, you get the flexibility that each field could be
> whatever type, but you lose the dynamicness (is that even a word?) of the
> keys.
> With Dict, it is the other way around. You can get a value by supplying a
> dynamic key, but all values in the Dict must be of the same type.
>
> --
> 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: Passing properties as arguments to messages?

2016-11-22 Thread Wouter In t Velt
PS: the function definition should not be capitalized, but should be called 
"animateProperty" of course

-- 
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: Passing properties as arguments to messages?

2016-11-22 Thread Wouter In t Velt
There is a way to make it work, but it will be a lot more verbose/ ugly/ 
overengineered. Your signature would need to look something like this:

AnimateProperty : Model -> (Model -> Style) -> (Style -> Model -> Model) -> 
Msg -> (Model, Msg)
AnimateProperty = model funcToExtractStyle funcToUpdateStyle animMsg =
  ...

-- call this as follows
(newModel, newCmd) = 
  animateProperty 
model 
(.answerTextStyle)
(\newStyle a -> { a | answerTextStyle = newStyle } )

And it will only work if all your properties are of the same type.
And if they are all of the same type, you would be better off to put all 
your styles in a `Dict`, which would make the `AnimateProperty` a lot 
cleaner.

-- 
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: Passing properties as arguments to messages?

2016-11-22 Thread Thomas Coopman
You can also extract getting the model property in a separate function, so
that you don't have to duplicate it completely.

On Mon, 21 Nov 2016 at 23:59 'Rupert Smith' via Elm Discuss <
elm-discuss@googlegroups.com> wrote:

> On Monday, November 21, 2016 at 6:27:40 PM UTC, Rex van der Spuy wrote:
>
> Is it possible to pass model properties as message arguments and use those
> arguments to construct a new model?
>
>
> Could use a Dict instead of properties?
>
> --
> 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.