[Haskell-begin] Re: For starters...
Greg Fitzgerald
garious at gmail.com
Fri Jul 18 13:59:35 EDT 2008
>> Is there any good tutorial on arrows?
> Ross Paterson. Arrows and Computation.
> http://www.soi.city.ac.uk/~ross/papers/fop.html<http://www.soi.city.ac.uk/%7Eross/papers/fop.html>
If you're new to Haskell, I'm guessing you're looking at the instance of
Arrow for ordinary functions, so that you can write in the point-free style.
instance Arrow (->) where
arr f = f
f >>> g = g . f
first f = f *** id
second f = id *** f
(***) f g ~(x,y) = (f x, g y)
If so, Ross Paterson's paper may scare you off. I'm not aware of any good
tutorial for ordinary functions - maybe because using arrows this way is
sort of a point-free programming gimmick. Anyway, here's my attempt at a
quick tutorial of the Arrow combinators for ordinary functions.
-- Pass input to one function, then its output to another
(f >>> g) x == g (f x)
-- Pass two inputs to two functions
(f *** g) ~(x,y) == (f x, g y)
-- Pass one input to both functions
(f &&& g) x == (f x, g x)
-- Apply function to only first of two inputs
(first f) (x,y) == (f x, y)
-- Apply function to only second of two inputs
(second f) (x,y) == (x, f y)
The pictures on this page are helpful:
http://www.haskell.org/arrows/
Arrows are more interesting when composing more abstract things where it
doesn't make sense to give the user access to inputs and outputs, such as
modeling circuits where the inputs are wires. Lots of good examples in the
paper apfelmus recommended.
-Greg
On Fri, Jul 18, 2008 at 1:33 AM, apfelmus wrote:
> Rafael Gustavo da Cunha Pereira Pinto wrote:
>
>> Is there any good tutorial on arrows?
>>
>
> I found
>
> Ross Paterson. Arrows and Computation.
> http://www.soi.city.ac.uk/~ross/papers/fop.html<http://www.soi.city.ac.uk/%7Eross/papers/fop.html>
>
> to be pretty good.
>
>
> Regards,
> apfelmus
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20080718/6e328179/attachment-0001.htm
More information about the Beginners
mailing list