You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Was wondering if this could be added to the compiler:
pubtypeBeing{Person(name:String,age:Int,is_happy:Bool)// imagine this type having a gazillion fieldsDog(name:String,age:Int,is_happy:Bool)}pubfnhave_birthday(being){// It's a birthday, so increment their age and make them happycasebeing{Dog(..)asdog->Dog(..dog,age:dog.age+1,is_happy:True)Person(..)asperson->Person(..person,age:person.age+1,is_happy:True)}}
This leads to
[gleam] error: Unsafe record update
┌─ ./src/playground.gleam:10:23
│
10 │ Dog(..) as dog -> Dog(..dog, age: dog.age + 1, is_happy: True)
│ ^^^ I can't tell this is always the right constructor
This type has multiple constructors so it cannot be safely updated.
If this value was one of the other variants then the update would be
produce incorrect results.
Consider pattern matching on it with a case expression and then
constructing a new record with its values.
Now I already pattern-matched on it and the compiler could know it's a dog. If the Dog would have lot's of fields then writing out every field becomes tedious.
The text was updated successfully, but these errors were encountered:
Was wondering if this could be added to the compiler:
This leads to
Now I already pattern-matched on it and the compiler could know it's a dog. If the Dog would have lot's of fields then writing out every field becomes tedious.
The text was updated successfully, but these errors were encountered: