# does this function exist already? (a -> b -> c) -> (d -> b) -> (( a -> d -> c )) Classic List Threaded 5 messages Open this post in threaded view
|

## does this function exist already? (a -> b -> c) -> (d -> b) -> (( a -> d -> c ))

 [Note, total newbie to mailing lists in general, and beginner in haskell as one might have surmised ^^ hopefully I'm doing the right thing here with this mail...]All, or virtually all in the title, but I'll develop. I wrote some useful function (which i rather awkwardly called "point2", for "(.) operator applied at the level of the second argument of the first function"). Here is its def:`point2 :: (a -> b -> c) -> (d -> b) -> (( a -> d -> c ))-- the double parentheses, totally optional and syntactically pointless, are just there to imply that the function is seen by we users as 'outputting' another function, even though said outputted function can be applied right away, of course, outputting then possibly c, or (d -> c) if partial application.-- I named the variables in the pattern like their respective types, for 'clarity'point2 f g a d = f a (g d)-- i originally wrote it in point free style using flip, from Data.Function (well, my own rebuilt wheel actually); so, alternate definition using flip == (\f y x -> f x y)point2 f g = flip (flip f . g)-- proof by decomposition: (or is it "composition", as we don't actually decompose?)-- f :: a -> b -> c-- flip f :: b -> a -> c-- flip f . g :: d -> a -> c-- flip (flip f . g) == f `point2` g :: a -> d -> c`anyways, it's pretty useful if you wanna combine f and g but g is meant to output the *second* argument of f, not the first, that is: `(f a) . g == (f `point2` g) a`in the first expression, "a" must necessarily be known and given to combine f and g in point-free style, whereas in the second one, "a" can be omitted, hence then we could write "foo = f `point2` g", which is way closer to the point-free style, way simpler to understand too in my opinion once you got the picture.If you got all I said above, my question is then to know if this point2 function already exists officially, coz I don't really wanna reinvent the wheel, plus I wonder how they called it ^^ I'm not really satisfied of "point2" as variable name. I'd love (.2) but it's not compatible with Haskell. ^^Also, same question for the following function (does it already exists?), again a sibling of (.), here, the purpose being to write h(a, b) = f (g(a, b))  in point-free style:`after2 :: (c -> d) -> (a -> b -> c) -> (( a -> b -> d ))after2 f g a b = f (g a b)-- its name implies an infix use, for example: h = f `after2` g`basically, if you know about Data.Function(on), it's a bit (one of) its opposite: `on` applies g to both arguments of f independently, before giving both results to the 2-ary function f, ie`(f `on` g) a b == f (g a) (g b)`I'm not entirely sure, but I think we could write:`f `after2` g == curry (f . (uncurry g))-- since:uncurry g :: (a,b) -> cf . uncurry g :: (a,b) -> dcurry (f . uncurry g) :: a -> b -> d`un/curry functions' defs, if needed:`curry :: ((a,b) -> c) -> a -> b -> ccurry f a b = f (a,b)-- curry f :: a -> b -> c when f :: (a,b) -> cuncurry :: (a -> b -> c) -> (a,b) -> cuncurry g (a,b) = g a b-- uncurry g :: (a,b) -> c when g :: a -> b -> c` _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Open this post in threaded view
|

## Re: does this function exist already? (a -> b -> c) -> (d -> b) -> (( a -> d -> c ))

 Hi, you might wanna take a look at Hoogle and Hayoo. They allow you to search for functions using names or type signatures. Hope this helps. _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Open this post in threaded view
|

## Re: does this function exist already? (a -> b -> c) -> (d -> b) -> (( a -> d -> c ))

 Hoogle was my first stop, didn't find anything, but Hayoo is much more complete, found all of it!"My" after2 has no less than 4 different synonymous: (oo), (.:), (comp2), (dot). and i checked my curry theory as correct.I found "point2" too right beside (.:), dubbed (.^).Those two inside a "pointlessfun" package (?) ^^Hence, thanks, I found what I needed. :)Do I need to close or mark the discussion as "solved" or something, somehow?Le vendredi 8 avril 2016, Sumit Sahrawat, Maths & Computing, IIT (BHU) <[hidden email]> a écrit :> Hi, you might wanna take a look at Hoogle and Hayoo. They allow you to search for functions using names or type signatures.>> Hope this helps. _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners