coconut icon indicating copy to clipboard operation
coconut copied to clipboard

Add haskell-like RecordWildCard syntax

Open hasufell opened this issue 7 years ago • 2 comments

See https://ocharles.org.uk/blog/posts/2014-12-04-record-wildcards.html

Example use case:

data Mydata(foo, bar)

foo = 1
bar = 2

new_data = Mydata({..})

Very useful for huge data structure that are e.g. tied to configuration, sql queries and so on.

I don't mind any other appropriate syntax other than {..}

hasufell avatar Mar 17 '17 21:03 hasufell

I think python's *args and **kwargs solves a similar issue.

cgarciae avatar Apr 09 '17 13:04 cgarciae

@cgarciae Possibly. The only case that isn't covered by *args and **kwargs is initializing the data type based on local/global variables. With *args you can use a list, and with **kwargs you can use a dictionary, but you can't use the local/global scope (**globals() and **locals() won't work, since the constructor will reject keys that don't correspond to arguments). What I'm not sure of, though, is how useful that use case actually is, and thus whether the feature would really be worth implementing.

evhub avatar Apr 10 '17 20:04 evhub