Hi,
hope its polite to bump up an old thread like this - if not, please accept my apologies. I have been struggling with the record update syntax for a while and wanted to share another use case which I think could be made better.
So let's say I want to populate a list of objects of the same type which have a lot of properties, most of which are kept default, e.g.
type alias Customer =
{ id : Int,
Name : String ,
-- Lots of other stuff
}
and I have a "constructor" function to build instances with default values, but never forget to fill in the id, e.g.
defaultCustomer : Int -> Customer
defaultCustomer id =
{ id = id,
Name = "",
-- lots of other initialization
}
now I would like to write things like
[
{ (defaultCustomer 1) | Name = "Smith" },
{ (defaultCustomer 2) | Name = "Jones" }
]
Which is not possible.
Now I have two options:
a) do not use a "constructor" and always write the records in full (not nice since they have a lot of fields which are mostly left default)
b) just have a template defaultCostumer : Customer and hope I will never forget to fill in the id (used in messages)
c) have a long "let" clause before defining the list
Neither of which seems nice.
I'll probably go with b), but if anyone has a nice suggestion how to enforce filling in a record in this way with the current syntax it would be very welcome.
And thanks for the work on elm - I am learning it and having fun with it!
Martin
but I tried to figure out where on GitHub should this be discussed and kind of failed...
(is it
https://github.com/elm-lang/elm-plans/issues/16 or