Re: [Haskell-cafe] lawless instances of Functor

2010-01-05 Thread Edward Kmett
Given fmap id = id, fmap (f . g) = fmap f . fmap g follows from the free theorem for fmap. This was published as an aside in a paper a long time back, but I forget where. -Edward Kmett On Mon, Jan 4, 2010 at 5:14 PM, Paul Brauner paul.brau...@loria.fr wrote: Hi, I'm trying to get a deep

Re: [Haskell-cafe] lawless instances of Functor

2010-01-05 Thread Ryan Ingram
On Mon, Jan 4, 2010 at 3:01 PM, Derek Elkins derek.a.elk...@gmail.com wrote: So without doing funky stuff involving bottoms and/or seq, I believe that fmap id = id implies the other functor law (in this case, not in the case of the general categorical notion of functor.) So lets play with

Re: [Haskell-cafe] lawless instances of Functor

2010-01-05 Thread Steffen Schuldenzucker
Brent Yorgey wrote: On Mon, Jan 04, 2010 at 11:49:33PM +0100, Steffen Schuldenzucker wrote: [...] As others have pointed out, this doesn't typecheck; but what it DOES show is that if we had a type class class Endofunctor a where efmap :: (a - a) - f a - f a then it would be

[Haskell-cafe] lawless instances of Functor

2010-01-04 Thread Paul Brauner
Hi, I'm trying to get a deep feeling of Functors (and then pointed Functors, Applicative Functors, etc.). To this end, I try to find lawless instances of Functor that satisfy one law but not the other. I've found one instance that satisfies fmap (f.g) = fmap f . fmap g but not fmap id = id:

Re: [Haskell-cafe] lawless instances of Functor

2010-01-04 Thread Steffen Schuldenzucker
Hi Paul, Paul Brauner wrote: Hi, I'm trying to get a deep feeling of Functors (and then pointed Functors, Applicative Functors, etc.). To this end, I try to find lawless instances of Functor that satisfy one law but not the other. I've found one instance that satisfies fmap (f.g) = fmap f

Re: [Haskell-cafe] lawless instances of Functor

2010-01-04 Thread Derek Elkins
On Tue, Jan 5, 2010 at 7:49 AM, Steffen Schuldenzucker sschuldenzuc...@uni-bonn.de wrote: Hi Paul, Paul Brauner wrote: Hi, I'm trying to get a deep feeling of Functors (and then pointed Functors, Applicative Functors, etc.). To this end, I try to find lawless instances of Functor that

Re: [Haskell-cafe] lawless instances of Functor

2010-01-04 Thread Jochem Berndsen
Steffen Schuldenzucker wrote: data Foo a = Foo a instance Functor Foo where fmap f (Foo x) = Foo . f . f $ x I think this doesn't typecheck. Cheers, Jochem -- Jochem Berndsen | joc...@functor.nl | joc...@牛在田里.com ___ Haskell-Cafe mailing

Re: [Haskell-cafe] lawless instances of Functor

2010-01-04 Thread Derek Elkins
On Tue, Jan 5, 2010 at 7:14 AM, Paul Brauner paul.brau...@loria.fr wrote: Hi, I'm trying to get a deep feeling of Functors (and then pointed Functors, Applicative Functors, etc.). To this end, I try to find lawless instances of Functor that satisfy one law but not the other. I've found one

Re: [Haskell-cafe] lawless instances of Functor

2010-01-04 Thread Dan Piponi
On Mon, Jan 4, 2010 at 3:01 PM, Derek Elkins derek.a.elk...@gmail.com wrote: Ignoring bottoms the free theorem for fmap can be written: If h . p = q . g then fmap h . fmap p = fmap q . fmap g When I play with http://haskell.as9x.info/ft.html I get examples that look more like: If fmap' has

Re: [Haskell-cafe] lawless instances of Functor

2010-01-04 Thread Brent Yorgey
On Mon, Jan 04, 2010 at 11:49:33PM +0100, Steffen Schuldenzucker wrote: data Foo a = Foo a instance Functor Foo where fmap f (Foo x) = Foo . f . f $ x Then: fmap id (Foo x) == Foo . id . id $ x == Foo x fmap (f . g) (Foo x) == Foo . f . g . f . g $ x fmap f . fmap g $

Re: [Haskell-cafe] lawless instances of Functor

2010-01-04 Thread Derek Elkins
On Tue, Jan 5, 2010 at 8:15 AM, Dan Piponi dpip...@gmail.com wrote: On Mon, Jan 4, 2010 at 3:01 PM, Derek Elkins derek.a.elk...@gmail.com wrote: Ignoring bottoms the free theorem for fmap can be written: If h . p = q . g then fmap h . fmap p = fmap q . fmap g When I play with

Re: [Haskell-cafe] lawless instances of Functor

2010-01-04 Thread Derek Elkins
On Tue, Jan 5, 2010 at 8:22 AM, Brent Yorgey byor...@seas.upenn.edu wrote: On Mon, Jan 04, 2010 at 11:49:33PM +0100, Steffen Schuldenzucker wrote: data Foo a = Foo a instance Functor Foo where     fmap f (Foo x) = Foo . f . f $ x Then: fmap id (Foo x) == Foo . id . id $ x == Foo x fmap

Re: [Haskell-cafe] lawless instances of Functor

2010-01-04 Thread Dan Piponi
On Mon, Jan 4, 2010 at 3:26 PM, Derek Elkins derek.a.elk...@gmail.com wrote: Yes, I have the same problem...Basically, I'm pretty sure the construction of that free theorem doesn't rely on any of the actual details... For a long time I've thought such a higher order free theorem must exist,

Re: [Haskell-cafe] lawless instances of Functor

2010-01-04 Thread Paul Brauner
Thanks. I was wondering if the free theorem of fmap entailed that implication, but I'm not used enough to decipher the output of the tool, neither am I able to generate it by hand. However, if this holds (law1 = law2), I wonder why this isn't some classic category theory result (maybe it is ?). I

Re: [Haskell-cafe] lawless instances of Functor

2010-01-04 Thread Dan Piponi
On Mon, Jan 4, 2010 at 4:15 PM, Paul Brauner paul.brau...@loria.fr wrote: I wonder why this isn't some classic category theory result (maybe it is ?) It doesn't hold in category theory in general. Haskell (or at least a certain subset) is special - many things that just *look* category

Re: [Haskell-cafe] lawless instances of Functor

2010-01-04 Thread ajb
G'day all. Quoting Derek Elkins derek.a.elk...@gmail.com: Ignoring bottoms the free theorem for fmap can be written: If h . p = q . g then fmap h . fmap p = fmap q . fmap g Setting p = id gives h . id = h = q . g fmap h . fmap id = fmap q . fmap g Using fmap id = id and h = q . g we get,