Are all arrows functors?

View: New views
6 Messages — Rating Filter:   Alert me  

Are all arrows functors?

by Neil Brown-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I was thinking about some of my code today, and I realised that where I
have an arrow in my code, A b c, the type (A b) is also a functor.  The
definition is (see
http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Arrow.html):

fmap = (^<<)
-- Or, in long form:
fmap f x = arr f <<< x

Out of curiosity, and since this is a typical haskell-cafe question,
does this definition of fmap hold for all arrows?

And is there a wiki page somewhere that has a table of all of these
Haskell type-classes (Functor, Monad, Category, Arrow, Applicative and
so on), and says that if you are an instance of class A you must have
some corresponding instance of B? (e.g. all Monads are Functors and
Applicatives)  I'm fairly certain my arrow isn't a Monad or Applicative,
although of course it must be a Category, given the type-class
dependency, but it would be nice when using one of these things to see
what other instances you should automatically supply.

Thanks,

Neil.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@...
http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: Are all arrows functors?

by jkff :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/11/3 Neil Brown <nccb2@...>:

> Hi,
>
> I was thinking about some of my code today, and I realised that where I have
> an arrow in my code, A b c, the type (A b) is also a functor.  The
> definition is (see
> http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Arrow.html):
>
> fmap = (^<<)
> -- Or, in long form:
> fmap f x = arr f <<< x
>
> Out of curiosity, and since this is a typical haskell-cafe question, does
> this definition of fmap hold for all arrows?
>
> And is there a wiki page somewhere that has a table of all of these Haskell
> type-classes (Functor, Monad, Category, Arrow, Applicative and so on), and
> says that if you are an instance of class A you must have some corresponding
> instance of B? (e.g. all Monads are Functors and Applicatives)  I'm fairly
> certain my arrow isn't a Monad or Applicative, although of course it must be
> a Category, given the type-class dependency, but it would be nice when using
> one of these things to see what other instances you should automatically
> supply.
>

What about the Typeclassopedia
(http://haskell.org/sitewiki/images/8/85/TMR-Issue13.pdf)?

> Thanks,
>
> Neil.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe@...
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



--
Eugene Kirpichov
Web IR developer, market.yandex.ru
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@...
http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: Are all arrows functors?

by Nicolas Pouillard-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Excerpts from Neil Brown's message of Tue Nov 03 13:45:42 +0100 2009:

> Hi,
>
> I was thinking about some of my code today, and I realised that where I
> have an arrow in my code, A b c, the type (A b) is also a functor.  The
> definition is (see
> http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Arrow.html):
>
> fmap = (^<<)
> -- Or, in long form:
> fmap f x = arr f <<< x
>
> Out of curiosity, and since this is a typical haskell-cafe question,
> does this definition of fmap hold for all arrows?

Yes, as shown by the 'WrappedArrow' newtype:

http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Applicative.html#t%3AWrappedMonad

--
Nicolas Pouillard
http://nicolaspouillard.fr
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@...
http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: Are all arrows functors?

by porges-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

See also the paper "Idioms are oblivious, arrows are meticulous,
monads are promiscuous" [1]. Functors can be extended to give
applicative functors (idioms) which can then be extended to arrows,
and then monads. So all arrows are also (applicative) functors.


[1]: http://homepages.inf.ed.ac.uk/wadler/papers/arrows-and-idioms/arrows-and-idioms.pdf
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@...
http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: Are all arrows functors?

by Andrew Coppin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Nicolas Pouillard wrote:

> Excerpts from Neil Brown's message of Tue Nov 03 13:45:42 +0100 2009:
>  
>> Hi,
>>
>> I was thinking about some of my code today, and I realised that where I
>> have an arrow in my code, A b c, the type (A b) is also a functor.  The
>> definition is (see
>> http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Arrow.html):
>>
>> fmap = (^<<)
>> -- Or, in long form:
>> fmap f x = arr f <<< x
>>
>> Out of curiosity, and since this is a typical haskell-cafe question,
>> does this definition of fmap hold for all arrows?
>>    
>
> Yes, as shown by the 'WrappedArrow' newtype:
>
> http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Applicative.html#t%3AWrappedMonad
>  

While I don't wish to suggest that "all arrows are functors" is false, I
think the argument "yes, because this library says so" is not too
strong. Let us not forget, according to *the libraries*, Double is in
Enum - which, I think you'll agree, is just weird...

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@...
http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: Are all arrows functors?

by David Menendez-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, Nov 5, 2009 at 4:34 PM, Andrew Coppin
<andrewcoppin@...> wrote:

> Nicolas Pouillard wrote:
>>
>> Excerpts from Neil Brown's message of Tue Nov 03 13:45:42 +0100 2009:
>>
>>>
>>> Hi,
>>>
>>> I was thinking about some of my code today, and I realised that where I
>>> have an arrow in my code, A b c, the type (A b) is also a functor.  The
>>> definition is (see
>>> http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Arrow.html):
>>>
>>> fmap = (^<<)
>>> -- Or, in long form:
>>> fmap f x = arr f <<< x
>>>
>>> Out of curiosity, and since this is a typical haskell-cafe question, does
>>> this definition of fmap hold for all arrows?
>>>
>>
>> Yes, as shown by the 'WrappedArrow' newtype:
>>
>>
>> http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Applicative.html#t%3AWrappedMonad
>>
>
> While I don't wish to suggest that "all arrows are functors" is false, I
> think the argument "yes, because this library says so" is not too strong.
> Let us not forget, according to *the libraries*, Double is in Enum - which,
> I think you'll agree, is just weird...

It's fairly simple to prove the functor laws using the arrow laws.
Among the nine laws for arrows are

    a >>> arr id = a
    a >>> arr f >>> arr g = a >>> arr (g . f)

Using the definition fmap f a = a >>> arr f, it's pretty simple to
prove the functor laws:

    fmap id = id
    fmap f . fmap g = fmap (f . g)

--
Dave Menendez <dave@...>
<http://www.eyrie.org/~zednenem/>
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@...
http://www.haskell.org/mailman/listinfo/haskell-cafe