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

Why is unsafe unsafe? #106

Open
Jashweii opened this issue Jul 16, 2023 · 0 comments
Open

Why is unsafe unsafe? #106

Jashweii opened this issue Jul 16, 2023 · 0 comments

Comments

@Jashweii
Copy link

Jashweii commented Jul 16, 2023

Edit - rephrased since I originally wrote this really unclearly
What exactly is unsafe about profunctor.unsafe?
The reasons given by the documentation are

  1. An implementation might unsafe coerce
  2. You might not give it a function that is operationally identity

But seemingly:

  1. This is the instance's/implementation's concern.
  2. It almost certainly can't make use of the function anyway, beyond seq.
    It has a coercible constraint, meaning it knows a function with the same type that IS operationally identity.

And even if 2 didn't apply, or if you really wanted something that looks like NewtypeConstructor #. p, with the "unsafe" bit being NewtypeConstructor isn't called and it's misleading if you pass in some other function, why couldn't this be a free function in an unsafe module which calls perfectly safe methods lcoerce/rcoerce, which either
A) Take Coercions without the coercible constraint
B) Take Proxys with the coercible constraint
C) Don't take any argument at all with the coercible constraint

This way at least the whole type class is perfectly safe.
Off topic addendum: Would it be better to have something like (Maybe (Coercion a b -> Coercion (p a x) (p b x)))? This way you can compose coercions where possible. But I don't know if there's any situation where you can more efficiently map a coercion but can't get a coercion back.

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

1 participant