The discussion was back and forth with SPJ and Richard Eisenberg during the

discussion about the creation of the roles machinery and Simon suggested

the shape it currently has to me last night.

Having this in the class is the only way that this can lift over an

'unknown' Functor in local scope, and permits users of a functor that is

polymorphic to get access to the O(1) coercion machinery.

Without it Coercible is almost completely useless in any code that has any

sort of polymorphism involved.

This is analogous to (<$), which was added to Functor explicitly because it

made an asymptotic performance difference in a large number of scenarios.

The reason this has to live in the class is analogous to how Data has to

hold the at-first-glance redundant dataCast1 and dataCast2, because it is

the only place the right things are known, despite them always being gcast1

and gcast2. See 7.4 in Scrap more boilerplate: reflection, zips, and

generalised casts<

http://research.microsoft.com/en-us/um/people/simonpj/papers/hmap/>

for

a discussion of an almost identical issue.

There is still some work to be done here. I definitely agree that we should

add some docs to it.

One of the reasons why we didn't in this initial commit is because there is

some of it still up in the air in terms of what is possible. The current

default definition is in terms of 'fmap coerce', so it'll currently work

with even 'illegal' functors that don't have a representational argument,

but the user doesn't see any improvement unless One of the reasons the

docs didn't go in with the first commit was that there is room for

improvement. *If* we can improve some things about Coercible inference we

may be able to upgrade it to actually use 'coerce' via a default signature.

-Edward

On Wed, Sep 25, 2013 at 12:41 AM, Johan Tibell <johan.tibell at gmail.com>wrote:

> Having coerce (!) show up in such a commonly used type class is a bit

> alarming. Was there a libraries discussion about this? At least we

> should add some docs to the method.

>

> On Wed, Sep 25, 2013 at 12:37 AM, <git at git.haskell.org> wrote:

> > Repository : ssh://git at git.haskell.org/base

> >

> > On branch : master

> > Link :

>

http://ghc.haskell.org/trac/ghc/changeset/3da4fd92e005cb9348ab2852d9268ad61ae1b347/base> >

> >>---------------------------------------------------------------

> >

> > commit 3da4fd92e005cb9348ab2852d9268ad61ae1b347

> > Author: Austin Seipp <austin at well-typed.com>

> > Date: Tue Sep 24 23:20:35 2013 -0500

> >

> > Add fmapCoerce to Functor class.

> >

> > This allows coercions to work under functors that are not locally

> known.

> >

> > Authored-by: Edward Kmett <ekmett at gmail.com>

> > Signed-off-by: Austin Seipp <austin at well-typed.com>

> >

> >

> >>---------------------------------------------------------------

> >

> > 3da4fd92e005cb9348ab2852d9268ad61ae1b347

> > GHC/Base.lhs | 4 +++-

> > 1 file changed, 3 insertions(+), 1 deletion(-)

> >

> > diff --git a/GHC/Base.lhs b/GHC/Base.lhs

> > index d876202..55172af 100644

> > --- a/GHC/Base.lhs

> > +++ b/GHC/Base.lhs

> > @@ -105,7 +105,6 @@ module GHC.Base

> > module GHC.Err -- import it explicitly

> > )

> > where

> > -

> > import GHC.Types

> > import GHC.Classes

> > import GHC.CString

> > @@ -186,6 +185,9 @@ class Functor f where

> > (<$) :: a -> f b -> f a

> > (<$) = fmap . const

> >

> > + fmapCoerce :: Coercible a b => f a -> f b

> > + fmapCoerce = fmap coerce

> > +

> > {- | The 'Monad' class defines the basic operations over a /monad/,

> > a concept from a branch of mathematics known as /category theory/.

> > From the perspective of a Haskell programmer, however, it is best to

> >

> > _______________________________________________

> > ghc-commits mailing list

> > ghc-commits at haskell.org

> >

http://www.haskell.org/mailman/listinfo/ghc-commits> _______________________________________________

> ghc-devs mailing list

> ghc-devs at haskell.org

>

http://www.haskell.org/mailman/listinfo/ghc-devs>

-------------- next part --------------

An HTML attachment was scrubbed...

URL: <

http://www.haskell.org/pipermail/ghc-devs/attachments/20130925/da9b62cf/attachment.htm>