-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
$.RecordType should also return a curried data constructor #66
Comments
@kedashoe, could you explain what you meant by this? |
Not sure when I'll be in front of a proper computer next, so I'll just respond now from memory as best I can.. First of all I don't think the end of that sentence makes any sense, so I'm not sure anyone can explain it :) But I think I was doing something like this // id :: a -> a
const id = a => return 10;
const $Point = $.RecordType({x: Number, y: Number});
let Point = function(x, y) { this.x = x; this.y = y };
let p = new Point(1, 2);
id(p); and the error message was telling me my StrMap was wrong (that code probably doesn't quite make sense, basically I was just forcing a typevar conflict). What I was trying to say here was maybe there would be a way to construct |
I think I see what you're getting at, Kevin (but correct me if I'm wrong). You're wanting to create a value of type In the post-#55 era we'd lose a lot by displaying name only.
The above would become:
|
I was hoping for
but yes, I think you've got the idea (and not critical to this issue, just loosely related) |
This is out of scope for sanctuary-def. |
@kedashoe, in sanctuary-js/sanctuary#206 (comment):
I've found myself doing this quite often:
It would be very cool to be able to define a record type and a curried function for creating values of that type in one go. We could achieve this by having
$.RecordType
return a(type, constructor)
tuple or by having it return a value which serves both roles, as Kevin suggested. The latter has the advantage of avoiding naming collisions and the awkward type names—such as$Repository
—they entail.Are we willing to rely on object enumeration order? If so, we could have
$.RecordType
continue to provide the current, elegant API. If not, we're forced to have it take a list of pairs:I could live with this, though I would miss the correspondence between the shape of the type definition and the shape of values of that type. Perhaps a better solution is to rely on object enumeration order and clearly document this assumption.
The text was updated successfully, but these errors were encountered: