I had two functions
f1:: String -> Int
f2:: String -> Int
f3:: String -> (Int,Int)
f3 = f1 &&& f2
then they was changed to String -> Maybe Int
f1:: String -> Maybe Int
f2:: String -> Maybe Int
f3:: String -> (Maybe Int,Maybe Int)
Is there pointfree way to get function
f4:: String -> Maybe (Int, Int)
So if both f1 and f2 return Just, f4 will also return Just otherwise Nothing
import Control.Arrow
import Control.Applicative
h :: (Applicative f) => (a -> f b) -> (a -> f c) -> a -> f (b, c)
h = liftA2 (liftA2 (,))
which is equal to h f g x = liftA2 (,) (f x) (g x)
You can get pointfree version using liftA2
, but I'm not sure if the point-free version is worth the trouble:
λ> :t \f1 f2 -> uncurry (liftA2 (,)) . (f1 &&& f2)
\f1 f2 -> uncurry (liftA2 (,)) . (f1 &&& f2)
:: Applicative f => (b1 -> f a) -> (b1 -> f b) -> b1 -> f (a, b)
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