
Hello all I skimmed several Arrow tutorial and looked at the pretty diagrams and thought to myself "Hmm, these guys seem to take input and produce output". But that's what a function does. So what's the fundamental difference between an arrow and a fuction?

martin
writes:
But that's what a function does. So what's the fundamental difference between an arrow and a fuction?
Arrows abstract functions, allowing you to have constructions like Kleisli, which are Arrows, but compose in the presence of effects using (<=<) rather than (.). John

John Wiegley
writes:
Arrows abstract functions, allowing you to have constructions like Kleisli, which are Arrows, but compose in the presence of effects using (<=<) rather than (.).
That is, you compose them using (<<<) as you would using any other Arrow, but the Arrow instance is using a different form of composition under the hood. John

Am 03/23/2015 um 09:57 PM schrieb John Wiegley:
martin
writes: But that's what a function does. So what's the fundamental difference between an arrow and a fuction?
Arrows abstract functions, allowing you to have constructions like Kleisli, which are Arrows, but compose in the presence of effects using (<=<) rather than (.).
I recall reading something like "under composition an arrow returns a new version of itself". It this correct? This would indeed be something a function does not do.

On 03/23/2015 04:43 PM, martin wrote:
Hello all
I skimmed several Arrow tutorial and looked at the pretty diagrams and thought to myself "Hmm, these guys seem to take input and produce output".
But that's what a function does. So what's the fundamental difference between an arrow and a fuction?
They're basically functions, and you won't steer yourself wrong thinking about them like that. By analogy, in Haskell, if you wanted to add two floating point numbers you would need to define a floating point addition: floatAdd :: Float -> Float -> Float Then if you wanted to add two integers, you'd need a second function: intAdd :: Int -> Int -> Int The prelude already abstracts this away for you -- both Int and Float are instances of the Num class, which gives you, (+) :: (Num a) => a -> a -> a So at that point, you might ask yourself, what's the point of a Num? Aren't they just (floating point, int, etc.) numbers? The answer is "yes," and you don't want to have twenty different addition functions for everything that is some kind of number, so it makes sense to group all number-things into one typeclass. Likewise, all function-things are grouped into the Arrow typeclass so that you can compose them without worrying about the exact type. Everything in the Arrow typeclass is some kind of function, and you can compose them with the Arrow class methods.
participants (3)
-
John Wiegley
-
martin
-
Michael Orlitzky