foundation
foundation copied to clipboard
curry & uncurry family of functions
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 ...
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?
Also, generalizing curry requires injections into the product type p, which require a new type class InjectInto{N} AFAIK.
One idea could be to have a Uncurryable{N} class for uncurrying. Not sure whether generalizing currying into a Curryable{N} class makes sense.
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.