-
Notifications
You must be signed in to change notification settings - Fork 21
Allow the construction of self-referential Ref
s
#21
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
Conversation
src/Effect/Ref.purs
Outdated
@@ -13,7 +13,12 @@ import Effect (Effect) | |||
foreign import data Ref :: Type -> Type | |||
|
|||
-- | Create a new mutable reference containing the specified value. | |||
foreign import new :: forall s. s -> Effect (Ref s) | |||
new :: forall s. s -> Effect (Ref s) | |||
new s = self (const s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like that new
requires an unnecessary closure allocation with const
on top of the ref allocation and then Effect thunk allocation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I guess the whole thing is FFI already so one more function won't do any harm.
What's the status of this PR? |
Is "forgotten entirely about" a valid status? 😄 It sounds like the review concern was addressed, but there's no explicit approval. |
This looks good to me, although I think I’d prefer the function was called |
Same. @garyb How quickly would you be able to update this PR? Or should someone else submit a PR to your branch to get the name changed? |
Done! I wonder if there's still a better name though, as |
Why? What about |
Looks like CI is failing because the tests weren't updated:
|
People use the phrase “tying the knot” to mean constructing a structure which references itself: https://wiki.haskell.org/Tying_the_Knot |
Let's assume you come to a language and codebase you've never seen before and you only see this: IMHO, I think the |
newWithSelf? |
Sure. |
Renamed again, and updated the tests this time! @JordanMartinez re: people coming to the library looking for this function, realistically I'm not sure how often that will happen. I needed to do this in Halogen, and used an Maybe there are some other uses cases for it though, I dunno. I've definitely used self referential I think providing a way to do it in the library rather than having to do an ad-hoc |
No description provided.