foundation icon indicating copy to clipboard operation
foundation copied to clipboard

curry & uncurry family of functions

Open vincenthz opened this issue 7 years ago • 4 comments

Currently defined in Prelude as:

curry :: ((a, b) -> c) -> a -> b -> c
uncurry :: (a -> b -> c) -> (a, b) -> c

uncurry{N} is available in Foundation.Collection.Zippable but should use the new abstraction from Foundation.Tuple using Fstable and Sndable.

Also curry3, curry4 ...

vincenthz avatar Apr 02 '17 12:04 vincenthz

I'd like to try my hand at this. Just one question: Am I correct in the assumption that uncurry{N} will only use the Nthable class up to N = 3 and for N >= 4 only tuples are supported?

ThreeFx avatar Jun 09 '17 11:06 ThreeFx

Also, generalizing curry requires injections into the product type p, which require a new type class InjectInto{N} AFAIK.

ThreeFx avatar Jun 09 '17 11:06 ThreeFx

One idea could be to have a Uncurryable{N} class for uncurrying. Not sure whether generalizing currying into a Curryable{N} class makes sense.

lortabac avatar Jun 09 '17 14:06 lortabac

Question with Uncurryable{N} is whether it is worth the effort. User-defined Product datatypes can be transformed to tuples using GHC.Generics, which kind of eliminates the point of generalizing uncurry{N}.

On a side note: @lortabac pointed out that (one of the few) useful cases for [Un]Curryable{N} might kick in when wanting to distinguish between lazy and strict tuples. Although in this case I don't know if it's worth the effort of maintaining both type classes for two instances each.

ThreeFx avatar Jun 09 '17 14:06 ThreeFx