I have a type
type alias WithStatus l =
{ l
| status :
Status
}
This extends a record with a status field.
Now I'd like to make a function that takes a record and gives it a particular status, so I made:
addStatus : Status -> l -> WithStatus l
addStatus status l =
{ l
| status =
status
}
However elm complains that l could potentially not be a record.
This is not a record, so it has no fields to update!
21|> { l
22| | status =
23| status
24| }
This `l` value is a:
l
But I need a record!
Which is true. However elm has no way of knowing that the l in the type alias is a record either, it checks for that on the use site. So it seems a little odd that it's complaining here.
Is there a way to express a function which takes any record l and adds a status?
You can do
which replaces an existing status, but the ability to introduce new fields in the way you were hoping isn't possible any more.
It used to be, from 0.7 until 0.16 (released in 2015) where it was removed because it wasn't felt to be actually all that useful: