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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Silent Leaf
[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) -> c
f . uncurry g :: (a,b) -> d
curry (f . uncurry g) :: a -> b -> d

un/curry functions' defs, if needed:
curry :: ((a,b) -> c) -> a -> b -> c
curry f a b = f (a,b)
-- curry f :: a -> b -> c when f :: (a,b) -> c
uncurry :: (a -> b -> c) -> (a,b) -> c
uncurry 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
Reply | Threaded
Open this post in threaded view
|

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

Sumit Sahrawat, Maths & Computing,
 IIT (BHU)

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
Reply | Threaded
Open this post in threaded view
|

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

Silent Leaf
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
Reply | Threaded
Open this post in threaded view
|

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

Silent Leaf
Ok thanks! By the way, I didn't know the formatting (especially, code/noncode distinction) was erased in the process of archiving my mail, sorry for the unfortunate, probable, unreadability of my first message.

Actually, I have another question that somewhat is in continuity, as regards one definition I found for after2 (with another name of course, though here it's irrelevant):
> after2 :: (c -> d) -> (a -> b -> c) -> a -> b -> d
> after2 f = ((f .) .)

I checked by recursion, mostly to actually understand why/how it works, and it's pretty cool, if I may.
> f :: c -> d
> (f .) :: (b -> c) -> (b -> d)
> ((f .) .) :: (a -> (b -> c)) -> (a -> (b -> d)) == (a -> b -> c) -> (a -> b -> d)

Or seen from another angle:
> f (g a b) :: d
> (f .) (g a) :: b -> d
> ((f .) .) g :: (a -> b -> d)

From there, I had the idea and desire to check if we could build a generalization of this operation, in this fashion:
> testOp :: Int -> (c -> d) -> ? --Here i'm stuck since it looks like it should basically be a sort of recursive type of function, or something??
> testOp 0 f = f
> testOp n f = ((testOp (n-1) f) .)

hence with this definition, (testOp 2) == after2 and (testOp 1) == (.)
Is this "testOp" writable? If so, what would it need?
Thanks in advance! :)

2016-04-09 0:09 GMT+02:00 Sumit Sahrawat, Maths & Computing, IIT (BHU) <[hidden email]>:

No need to do anything. On the list you can only send and receive emails.


2016-04-09 0:04 GMT+02:00 Silent Leaf <[hidden email]>:
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
Reply | Threaded
Open this post in threaded view
|

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

Silent Leaf
Thanks! I'll definitely look into it. :)


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners