Struct updater syntax #1670
Replies: 3 comments 6 replies
-
|
The only thing I can think is to allow parallel setting so we can produce more efficient code. |
Beta Was this translation helpful? Give feedback.
-
|
In my experience with immutable data in React, ;; To update (.city (.address person))
(match person
((Person name address age)
(.> person
(!name "Alice")
(!address (.> address
(!city "Portland")
(!zip "97201")))))) |
Beta Was this translation helpful? Give feedback.
-
|
Here is an idea for something that would work on union types even with anonymous fields: COALTON-USER> (coalton-toplevel
(define-type Point
(Point2 Integer Integer)
(Point3 Integer Integer Integer)))
; No values
COALTON-USER> (coalton-toplevel
(define (shift-right pnt)
(update pnt
(Point2 1+ _)
(Point3 1+ _ _)))
(define (zero-z pnt)
(swap pnt
(Point2 _ _)
(Point3 _ _ 0))))
|
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Coalton should support syntax for updating fields of structs to return new, updated, structs.
E.g.
But it would be nice if Coalton supported a standard syntax for updating structures to return a new structure.
This hypothetical syntax might look like this:
My personal preference would be for
(!x 30)in the above to return a function of typePt -> Ptso that common update and folding patterns could be supported:Such a change would dramatically reduce boilerplate when updating large structures.
The syntax itself isn't very important, anything that is agreeable to users would be cool.
Are there any obvious ick-factors here?
Beta Was this translation helpful? Give feedback.
All reactions