How to get two values ​​from one, point, in Haskell?

For example, if you set the value v and the function f , is there a way to get the (fv,v) point for free?

+6
source share
3 answers

Alternatively, note that for functions h and f with the corresponding types

 h >>= f = \w -> f (hw) w 

so you can write

 f >>= (,) 
+13
source
 import Control.Arrow (g &&& f) v = (gv, fv) -- ergo, (id &&& f) v = (v, fv) (f &&& id) v = (fv, v) 
+11
source

How about using Applicative instance for (->)

 liftA2 (,) id :: (a -> b) -> a -> (a, b) 

for instance

 liftA2 (,) id succ 5 >>> (5,6) 
+5
source

Source: https://habr.com/ru/post/976458/


All Articles