For example, given a value, v
, and a function f
, is there a way to get (f v,v)
point free?
Alternatively, note that for functions h
and f
with appropriate types,
h >>= f = \w -> f (h w) w
so you can write
f >>= (,)
import Control.Arrow
(g &&& f) v = (g v, f v)
-- ergo,
(id &&& f) v = (v, f v)
(f &&& id) v = (f v, v)
How about using the Applicative
instance for (->)
liftA2 (,) id :: (a -> b) -> a -> (a, b)
For example
liftA2 (,) id succ 5
>>> (5,6)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With