question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Currying error on the wrong side

See original GitHub issue

This story tracks back to the first release of F# where the function Async.Catch was added, using the type on the left for the “right” value.

This in a type system with HKT support is the wrong decision, as we’re interested in currying types, then we want to have the good value on the rightmost position.

Now, in F# land we don’t have real HKTs so that’s not a technical restriction, just theorotical at the moment.

So, people started adopting it, then the new Result type landed in F# and guess what? They did it again. Left type for the right type.

Now, people is asking for some Result functions added to F# core. This is when the problem becomes a real problem, because here we’re not talking about types, we’re talking about actual values.

For values, it’s fair to think that’s also convenient to curry on the good one. See this comment from @kspeakman https://github.com/fsharp/fslang-suggestions/issues/526#issuecomment-393539604

Now the problem is we still don’t know what would be the standard for F# it’s probably a bit early. Here in F#+ we did the either function with the error on the right, we can change it in V2 but now we’re about to ship bifoldables, so the question is do we want to swap the functions? If the answer is yes, we can still do it for v1.1 but not later.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:19 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
wallymathieucommented, Jan 23, 2020

Sounds like the logical choice then is to document the weirdness and live with it. It’s a bit of an ugly remnant, but what to do.

1reaction
gustycommented, Jan 21, 2020

as usually compiler helps you out with which if 'a and which is 'b.

Yes. But I would say this problem becomes important when writing generic code.

Let’s try to draft some consistency rules:

  • We assume Choice and Either types to have their types reversed.
  • When we create a fake HKT for an abstraction we put the arguments in the correct order.
  • Therefore, a Bifoldable<'T1,'T2> correspond to Choice<'T2,'T1> and Result<'T2,'T1>.
  • Also, Bifunctor should follow the same rules, but we’re a bit late as that would be a breaking change. Indeed this reveals that our bimap for Result is reversed, normally the first function maps on the Error.
  • Bifunctor and Bifoldable should be consistent as there are some rules involving both.
  • ArrowChoice is also affected, it looks like it is already reversed but I would say it needs to be reviewed.
  • All these changes would impact Lens.

We’re a bit late now, either we:

  1. Do reverse Bifoldable, it would be out of sync with other abstractions that will be corrected in v2.0
  2. Leave Bifoldable consistent with the existing abstractions. Eventually for v2.0 all will be swapped.
  3. We don’t add Bifoldable until v2.0 to avoid conflict.
  4. We do add Bifoldable but not the instances for Either and Choice which are the conflicting ones.

Thoughts?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Something is wrong with currying/uncurrying · Issue #1836
What I mean is: I think it is possible now that uncurry or curry return functions not expected by the compiler, as they...
Read more >
Javascript currying pattern: getting error while calling function
I am trying to implement currying pattern for sum multiplication in my simple program. For that, I have defined one generic curry function...
Read more >
Currying
Currying is an advanced technique of working with functions. It's used not only in JavaScript, but in other languages as well.
Read more >
Understanding JavaScript currying
Currying simply means evaluating functions with multiple arguments and decomposing them into a sequence of functions with a single argument. In ...
Read more >
Currying in Lua : r/lua
I'm pretty new to Lua so please excuse any obvious oversights. Is there a consensus on the right way to curry an existing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found