Re: [elm-discuss] Unexpected error when parsing what seems to be reasonable code (Bug in parser maybe?)

2017-04-23 Thread Ilias Van Peer
If I'm not mistaken, this isn't so much about nested records as it is about 
referencing a qualified record in a record update expression.

This seems related to - but not exactly the same thing as 
- https://github.com/elm-lang/elm-compiler/issues/1549

So yeah, you could either create a local binding for it, use an extra 
helper function like Peter described, or expose `defaultViewConfig` in your 
imports so you can use it unqualified.

I've created a new issue for this 
- https://github.com/elm-lang/elm-compiler/issues/1587

Op zondag 23 april 2017 09:42:12 UTC+2 schreef Peter Damoc:
>
> On Sat, Apr 22, 2017 at 11:50 AM, Dwayne Crooks  > wrote:
>
>> 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?
>>
>> This is related to an active topic around record update syntax. 
> In short, currently it is not allowed to directly update nested records. ({ 
> Rating.defaultViewConfig | readOnly = model.readOnly } is invalid syntax) 
> The temporary solution is the one you stumbled upon: creating an alias for 
> the nested record. 
>
> Another solution would be to use custom functions:
>
>
> updateReadOnly : { a | readOnly : Bool } -> Bool -> a
> updateReadOnly rec readOnly =
> { rec | readOnly = readOnly }
>
> and then use it like: 
>
> ratingViewConfig =
> updateReadOnly Rating.defaultViewConfig True
>
>
> -- 
> There is NO FATE, we are the creators.
> blog: http://damoc.ro/
>

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

2017-04-23 Thread Peter Damoc
On Sat, Apr 22, 2017 at 11:50 AM, Dwayne Crooks 
wrote:

> 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?
>
> This is related to an active topic around record update syntax.
In short, currently it is not allowed to directly update nested records. ({
Rating.defaultViewConfig | readOnly = model.readOnly } is invalid syntax)
The temporary solution is the one you stumbled upon: creating an alias for
the nested record.

Another solution would be to use custom functions:


updateReadOnly : { a | readOnly : Bool } -> Bool -> a
updateReadOnly rec readOnly =
{ rec | readOnly = readOnly }

and then use it like:

ratingViewConfig =
updateReadOnly Rating.defaultViewConfig True


-- 
There is NO FATE, we are the creators.
blog: http://damoc.ro/

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