问题
For example, given a value, v
, and a function f
, is there a way to get (f v,v)
point free?
回答1:
Alternatively, note that for functions h
and f
with appropriate types,
h >>= f = \w -> f (h w) w
so you can write
f >>= (,)
回答2:
import Control.Arrow
(g &&& f) v = (g v, f v)
-- ergo,
(id &&& f) v = (v, f v)
(f &&& id) v = (f v, v)
回答3:
How about using the Applicative
instance for (->)
liftA2 (,) id :: (a -> b) -> a -> (a, b)
For example
liftA2 (,) id succ 5
>>> (5,6)
来源:https://stackoverflow.com/questions/26266825/how-to-get-two-values-from-one-point-free-in-haskell