For a function f :: a -> b -> c
is it possible to write a function g, so that the call (f g
) has type c
?
Specifically, if I have a data Type data Example = Example String String
the constructor Example
is of Type String -> String -> Example
, so is there a way for a function to generate both arguments "at once" without having to return a tuple and separating it or something similar?
I tried having g
as g :: a -> b
, but that doesn't work (and doesn't make sense, because for f
there is a value for a necessary and g
doesn't encode have any value for a
), but from the typing alone, this seems to be the only reasonable choice as a type of g
.
Nope. You could pass f
to another function, though – maybe g
itself, maybe something else like uncurry
.
ghci> :t uncurry f
uncurry f :: (a, b) -> c
ghci> let g = ("foo", 5)
ghci> uncurry f g
ghci> let g f = f "foo" 5
ghci> g f