Arrows that are also Functors

Edward Kmett ekmett at gmail.com
Tue Apr 19 23:40:20 CEST 2011


Er...

id ^<< g = arr id <<< g = arr id . g = id . g = g = id g



On Tue, Apr 19, 2011 at 12:32 PM, Edward Kmett <ekmett at gmail.com> wrote:

> On Tue, Apr 19, 2011 at 11:29 AM, Henning Thielemann <
> lemming at henning-thielemann.de> wrote:
>
>>
>> Is it common to make a type an instance of both Arrow and Functor type
>> class? If a type is both instance of Arrow and Functor, would you expect
>> that fmap = (^<<) ? If yes, how about adding this as expected law to the
>> Control.Arrow documentation?
>
>
> For any instance of Functor that is also an Arrow this must hold already
> given existing laws.
>
> One (particularly obvious) arrow law is that
>
> arr id = id
>
> This law states the fact that arr is the Functor from the category of
> Haskell types to your arrow category.
>
> Given that:
>
> id ^<< g = arr id <<< g = g . arr id = g . id = g = id g
>
> we can see (^<<) id = id is satisfied. The "second Functor law" comes for
> free given (^<<) id = id, and the free theorem for (^<<), so (^<<) is
> admissable as a definition for fmap.
>
> Finally, valid Functor instances for a given type are unique.
>
> This also follows from the free theorem for fmap and the side condition
> that fmap id = id and has been worked through here on the cafe before. I
> believe it was done most recently by Russell O'Connor.
>
> So fmap = (^<<) must hold for any type that is both a valid instance of
> Arrow and Functor.
>
> The free theorem for fmap does all your work for you and no new laws need
> to be placed on the books.
>
> -Edward
>
>
>> Same question for Applicative functors and liftA2 (,) = (&&&). (Btw.
>> Control.Arrow haddock documentation does not mention any Arrow law so far.)
>>
>> _______________________________________________
>> Libraries mailing list
>> Libraries at haskell.org
>> http://www.haskell.org/mailman/listinfo/libraries
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20110419/b698e62f/attachment-0001.htm>


More information about the Libraries mailing list