Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move extensibility to use-site #240

Open
robinheghan opened this issue Jan 23, 2024 · 6 comments
Open

Move extensibility to use-site #240

robinheghan opened this issue Jan 23, 2024 · 6 comments

Comments

@robinheghan
Copy link
Member

robinheghan commented Jan 23, 2024

Copying this idea from elm slack, by Changlin Li

[…] RE Roc, I agree I've been meaning to try it out. There's one small UX thing about composability that I wish Roc did differently (essentially I don't think that type synonyms themselves should express whether they are extensible, but the extensibility should be delayed to the call site, so that e.g. in hypothetical Elm syntax type MyRecord = {a : Int, b : String} could be used at the callsite as myFunctionWithExtensibleRecord :: a ++ MyRecord -> Int, which would also allow type synonyms to be nicely merged together (e.g. type MyBigRecord = MyRecord ++ MyOtherRecord) without needing to decide beforehand which type synonyms are meant to be extensible and which aren't, since that's usually practically ends up being more relevant for callsites

@boxed
Copy link

boxed commented Jan 23, 2024

Minor quibble: I find ++ to be a weird syntax. That's the append operator right? Append isn't commutative.

I like this a lot. It's a lot nicer than going around copy-pasting {a | foo: int, bar: baz} in many places.

@blaix
Copy link
Contributor

blaix commented Jan 26, 2024

Minor quibble: I find ++ to be a weird syntax. That's the append operator right? Append isn't commutative.

What about javsacript's spread syntax?

Something like: { a : String, ...OtherRecord }

Could be used in pattern matching too: { a, ...everythingElse }, [ "blog", "post", ...path ] :)

I like this a lot.

Me too!

My gut reaction was wondering if this could be abused. In other words, is keeping it explicit per record protecting us from ourselves? But I don't think so.

@boxed
Copy link

boxed commented Jan 26, 2024

@blaix it sounds like you are talking's about two different things.

@blaix
Copy link
Contributor

blaix commented Jan 27, 2024

Very likely! I'm easily confused. Happy to delete if I'm talking nonsense.

@robinheghan
Copy link
Member Author

robinheghan commented Jan 27, 2024

If I'm understanding @blaix correctly, you'd be able to extend a record literal type like { ...Record1, ...Record2 } in addition to doing it inline, which his first example is doing. Is that right, @blaix ?

For records it works fine. For Custom Types/Tags, I guess it could work like | Tag1 | Tag2 | ...TagAlias and | ...Alias1 | ...Alias2?

I do like the idea of matching this up with pattern matching, but I think that's a discussion we can have on Zulip.

@blaix
Copy link
Contributor

blaix commented Jan 27, 2024

Right, I think I focused too much on the A = B ++ C part of the example. I see now where I misunderstood the function signature part of the suggestion. I guess that would look something like greet : { Named, ... } -> String.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants