
I have defined a bunch of functions like this: -- | Move the fourth argument to the first place rotate4 :: (a -> b -> c -> d -> e) -> (d -> a -> b -> c -> e) -- | Reverse four arguments flip4 :: (a -> b -> c -> d -> e) -> (d -> c -> b -> a -> e) I decided to upload this as a library to hackage, as I personally find it useful, especially for writing FFI bindings. It seems like I can't be the first to write a library like this though, am I missing something obvious? Is this useful or stupid? Does it exist already? Full definition here: https://github.com/christian-marie/flippers/blob/master/src/Control/Flippers...

On 14 January 2014 16:48, Christian Marie
I have defined a bunch of functions like this:
-- | Move the fourth argument to the first place rotate4 :: (a -> b -> c -> d -> e) -> (d -> a -> b -> c -> e)
-- | Reverse four arguments flip4 :: (a -> b -> c -> d -> e) -> (d -> c -> b -> a -> e)
I decided to upload this as a library to hackage, as I personally find it useful, especially for writing FFI bindings.
It seems like I can't be the first to write a library like this though, am I missing something obvious? Is this useful or stupid? Does it exist already?
Full definition here:
https://github.com/christian-marie/flippers/blob/master/src/Control/Flippers...
Except for completeness, I don't see the point of rotate1 and flip1. I'd also be tempted to possibly shift the module to Data.Function.Flippers (as flip is re-exported by Data.Function in base, and it seems like a more valid location to me). That said, whilst I do use flip upon occasion, I think in the general case it'd be too easy to abuse these kinds of functions and could be more difficult to work any errors if you used the wrong one or had some arguments in the wrong order. -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com http://IvanMiljenovic.wordpress.com

On 01/14/2014 01:06 AM, Ivan Lazar Miljenovic wrote:
On 14 January 2014 16:48, Christian Marie
wrote: I have defined a bunch of functions like this:
-- | Move the fourth argument to the first place rotate4 :: (a -> b -> c -> d -> e) -> (d -> a -> b -> c -> e)
-- | Reverse four arguments flip4 :: (a -> b -> c -> d -> e) -> (d -> c -> b -> a -> e)
I decided to upload this as a library to hackage, as I personally find it useful, especially for writing FFI bindings.
It seems like I can't be the first to write a library like this though, am I missing something obvious? Is this useful or stupid? Does it exist already?
Full definition here:
https://github.com/christian-marie/flippers/blob/master/src/Control/Flippers...
Except for completeness, I don't see the point of rotate1 and flip1.
It could be nice if you're attempting something insane with e.g. template haskell and don't want n=1 to be a special case.

On 14/01/14 15:48, Christian Marie wrote:
I have defined a bunch of functions like this:
-- | Move the fourth argument to the first place rotate4 :: (a -> b -> c -> d -> e) -> (d -> a -> b -> c -> e)
-- | Reverse four arguments flip4 :: (a -> b -> c -> d -> e) -> (d -> c -> b -> a -> e)
I decided to upload this as a library to hackage, as I personally find it useful, especially for writing FFI bindings.
It seems like I can't be the first to write a library like this though, am I missing something obvious? Is this useful or stupid? Does it exist already?
Full definition here:
https://github.com/christian-marie/flippers/blob/master/src/Control/Flippers...
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe Why not generalise to any functor?
let flip f a = fmap ($a) f -- Tony Morris http://tmorris.net/

On Tue, Jan 14, 2014 at 04:57:14PM +1000, Tony Morris wrote:
Why not generalise to any functor? let flip f a = fmap ($a) f
I didn't think of that, I suppose. Now that I do, it seems to be a tradeoff between (arguably) less immediately obvious type signatures and something. I can't actually think of what that something is yet. Can you think of a real world use for a functor flip where normal flip wouldn't do?

On Tue, Jan 14, 2014 at 3:30 PM, Christian Marie
On Tue, Jan 14, 2014 at 04:57:14PM +1000, Tony Morris wrote:
Why not generalise to any functor? let flip f a = fmap ($a) f
I didn't think of that, I suppose.
Now that I do, it seems to be a tradeoff between (arguably) less immediately obvious type signatures and something.
I can't actually think of what that something is yet. Can you think of a real world use for a functor flip where normal flip wouldn't do?
I know I've written "fmap ($a) f" in the past, so I guess any of those would be a use case for a functor flip. On the other hand, it's only a few characters longer than flip, and arguably more clear, so I'm not convinced that generalizing flip is useful. YMMV.

On Wed, Jan 15, 2014 at 12:30 AM, Christian Marie
On Tue, Jan 14, 2014 at 04:57:14PM +1000, Tony Morris wrote:
Why not generalise to any functor? let flip f a = fmap ($a) f
I didn't think of that, I suppose.
Now that I do, it seems to be a tradeoff between (arguably) less immediately obvious type signatures and something.
I can't actually think of what that something is yet. Can you think of a real world use for a functor flip where normal flip wouldn't do?
I think it's mostly a skeleton to use for generalizing flip. Right now, you have \f a -> fmap ($a) f :: Functor f => f (a -> b) -> a -> f b so if you take (f ~ (->) c), you have \f a -> fmap ($a) f :: (c -> a -> b) -> (a -> c -> b) For flips of higher arities, you would choose a different `f`, like (f ~ (->) d . (->) c): \f a -> fmap ($a) f :: (c -> d -> a -> b) -> (a -> c -> d -> b)

While I don't think the overall idea is good*, I do wonder if the explicit numbers in the names could be removed. Here are some approaches to writing N-ary zipWith that might give you inspiration: https://gist.github.com/dagit/6082516 https://gist.github.com/dagit/8428444 Both have links to the original sources. The first one depends on closed type families and the other one still uses numerals but they are just names for special functions that makes it all hold together. * I don't think we should encourage use of things like flip8 in 'real code' because it's very likely to make the code completely incomprehensible. I DO think it's a fun and interesting exercise to generalizing flip to N-ary. Jason

On Mon, Jan 13, 2014 at 10:57 PM, Tony Morris
On 14/01/14 15:48, Christian Marie wrote:
I have defined a bunch of functions like this:
-- | Move the fourth argument to the first place rotate4 :: (a -> b -> c -> d -> e) -> (d -> a -> b -> c -> e)
-- | Reverse four arguments flip4 :: (a -> b -> c -> d -> e) -> (d -> c -> b -> a -> e)
I decided to upload this as a library to hackage, as I personally find it useful, especially for writing FFI bindings.
It seems like I can't be the first to write a library like this though, am I missing something obvious? Is this useful or stupid? Does it exist already?
Full definition here: https://github.com/christian-marie/flippers/blob/master/src/Control/Flippers...
_______________________________________________ Haskell-Cafe mailing listHaskell-Cafe@haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe
Why not generalise to any functor?
let flip f a = fmap ($a) f
I don't see that operator as "flip-like", personally. It might behave as flip in the case of the function functor , but that intuition does not carry over to things like fmap ($a) [f, g, h] = [f a, g a, h a] I'd call it "funder", personally.

On Tue, Jan 14, 2014 at 04:57:14PM +1000, Tony Morris wrote:
Why not generalise to any functor?
let flip f a = fmap ($a) f
FYI, this is Control.Lens.?? http://hackage.haskell.org/package/lens-3.9.2/docs/src/Control-Lens-Combinat... Tom

Indeed! I offered the question as a coaching exercise :) On 15/01/14 19:56, Tom Ellis wrote:
On Tue, Jan 14, 2014 at 04:57:14PM +1000, Tony Morris wrote:
Why not generalise to any functor?
let flip f a = fmap ($a) f FYI, this is Control.Lens.??
http://hackage.haskell.org/package/lens-3.9.2/docs/src/Control-Lens-Combinat...
Tom
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Tony Morris http://tmorris.net/
participants (10)
-
Alexander Solla
-
Christian Marie
-
Ivan Lazar Miljenovic
-
Jason Dagit
-
John Lato
-
João Cristóvão
-
Michael Orlitzky
-
Stijn van Drongelen
-
Tom Ellis
-
Tony Morris