Pointless functors

Bonjour café, Are there any functors f for which no point/pure/return :: a -> f a exists? Thank you, Martijn.

On Fri, 13 Mar 2009 14:32:23 +0000
Ross Paterson
On Fri, Mar 13, 2009 at 03:18:15PM +0100, Martijn van Steenbergen wrote:
Are there any functors f for which no point/pure/return :: a -> f a exists?
No. Choose an arbitrary element shape :: f () and define
point x = fmap (const x) shape
This suggests a fun way to define a monad for a functor F: -- Does nothing, has no effect, and returns () noOp :: F () noOp = ... instance Monad F where return x = fmap (const x) noOp (<<=) f x = ... I think noOp would be a nice addition to the Monad class, as well. -- Robin

'An arbitrary element' means 'undefined will suffice'
point x = fmap (const x) undefined
2009/3/13 Ross Paterson
On Fri, Mar 13, 2009 at 03:18:15PM +0100, Martijn van Steenbergen wrote:
Are there any functors f for which no point/pure/return :: a -> f a exists?
No. Choose an arbitrary element shape :: f () and define
point x = fmap (const x) shape _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Eugene Kirpichov Web IR developer, market.yandex.ru

For most functors, that is equivalent to
point x = undefined
But by that logic, everything is a member of every typeclass...
--
Robin
On Fri, 13 Mar 2009 17:35:31 +0300
Eugene Kirpichov
'An arbitrary element' means 'undefined will suffice'
point x = fmap (const x) undefined
2009/3/13 Ross Paterson
: On Fri, Mar 13, 2009 at 03:18:15PM +0100, Martijn van Steenbergen wrote:
Are there any functors f for which no point/pure/return :: a -> f a exists?
No. Choose an arbitrary element shape :: f () and define
point x = fmap (const x) shape _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Thursday 12 March 2009 10:30:47 pm Robin Green wrote:
For most functors, that is equivalent to
point x = undefined
But by that logic, everything is a member of every typeclass...
There are some cases where expected laws will prevent that. For instance, If you try to make a monad like: instance Monad m where return = undefined m >>= f = undefined Then it will fail the law: m >>= return = m unless the only possible value of m is undefined (that is, m a is uninhabited except for bottom). In the case of pointed functors, the point is supposed to be a natural transformation from the identity functor to the functor in question, so: fmap f . point = point . f which always works with 'point = undefined' as long as 'fmap f' is strict (which it's basically required to be, since it must satisfy fmap id = id, and id is strict). Of course, the fact that it satisfies the relevant law doesn't make it less worthless as an instance. To make things less trivial, one might restrict himself to definitions that would work in a total language, and then it's easy to come up with examples of functors that aren't pointed. For instance, one can write the following in Agda: data Void (a : Set) : Set where -- empty mapVoid : {a b : Set} -> (a -> b) -> Void a -> Void b mapVoid f () -- empty function pointVoid : {a : Set} -> a -> Void a pointVoid = ? -- can't be written -- Dan

On Fri, Mar 13, 2009 at 04:11:57PM +0100, Martijn van Steenbergen wrote:
Eugene Kirpichov wrote:
'An arbitrary element' means 'undefined will suffice'
point x = fmap (const x) undefined
Prelude> fmap (const True) undefined :: [Bool] *** Exception: Prelude.undefined
Or is that not what you mean?
OK, an arbitrary maximal element.

Well, yes; then, that means that "an arbitrary element" is also false:
you can't just take an arbitrary element and hope that works well.
Then the original question must be reformulated:
- Are there any functors for which there exists at least one
non-bottom value of type 'f a' for some a, but there does not exist a
function point :: a -> f a such that (a != _|_) => (point a != _|_).
2009/3/13 Brent Yorgey
On Fri, Mar 13, 2009 at 05:35:31PM +0300, Eugene Kirpichov wrote:
'An arbitrary element' means 'undefined will suffice'
point x = fmap (const x) undefined
This is false.
Prelude> fmap (const 1) [()] [1] Prelude> fmap (const 1) undefined *** Exception: Prelude.undefined
-Brent
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Eugene Kirpichov Web IR developer, market.yandex.ru

Ross Paterson wrote:
No. Choose an arbitrary element shape :: f () and define point x = fmap (const x) shape
Interesting. Is the arbitrariness of the shape some sort of evidence that Pointed is not really a very useful class in its own right? Certainly, the shape does matter if you plan to progress to non-trivial Applicative or Monad instances. For example, the non-determinism monad requires shape = [()], while the ZipList applicative functor requires shape = repeat (). Eugene Kirpichov wrote:
'An arbitrary element' means 'undefined will suffice' point x = fmap (const x) undefined
Well, that would rather limit the possible Applicative instances. :-) (Consider the Applicative law: fmap g x = pure g <*> x) Brent Yorgey wrote:
Prelude> fmap (const 1) [()] [1] Prelude> fmap (const 1) undefined *** Exception: Prelude.undefined
True, but as far as I can tell, that doesn't violate any laws of the Pointed class. To put it crudely, if [] is as good as [()], then how is undefined any worse?

On Sat, 2009-03-14 at 02:12 +1000, Matthew Brecknell wrote:
Ross Paterson wrote:
No. Choose an arbitrary element shape :: f () and define point x = fmap (const x) shape
Interesting. Is the arbitrariness of the shape some sort of evidence that Pointed is not really a very useful class in its own right?
A simpler bit of evidence is that the only law I can think of for point (in its own right) is fmap f . point = point . f which we get free anyway. jcc

On Sat, Mar 14, 2009 at 02:12:45AM +1000, Matthew Brecknell wrote:
Ross Paterson wrote:
No. Choose an arbitrary element shape :: f () and define point x = fmap (const x) shape
Interesting. Is the arbitrariness of the shape some sort of evidence that Pointed is not really a very useful class in its own right?
Not useless, but equivalent to class Functor f => Pointed f where unit :: f () Naturality of point does the rest. But not all definitions of unit are equally useful.

On 13 Mar 2009, at 14:32, Ross Paterson wrote:
On Fri, Mar 13, 2009 at 03:18:15PM +0100, Martijn van Steenbergen wrote:
Are there any functors f for which no point/pure/return :: a -> f a exists?
No. Choose an arbitrary element shape :: f () and define
point x = fmap (const x) shape
Correspondingly, consider the functor Const Void. Cheers Conor

On Fri, Mar 13, 2009 at 02:32:23PM +0000, Ross Paterson wrote:
On Fri, Mar 13, 2009 at 03:18:15PM +0100, Martijn van Steenbergen wrote:
Are there any functors f for which no point/pure/return :: a -> f a exists?
No. Choose an arbitrary element shape :: f () and define
point x = fmap (const x) shape
But since f may be polymorphic in some other types, it may not be possible to choose such an arbitrary shape. For example, ((,) w) is a Functor but it is not possible to define a function point :: a -> (w,a) without (1) using undefined for the value of type w, or (2) putting some sort of constraint on w which lets us choose a canonical value of type w, such as Monoid. -Brent
participants (9)
-
Brent Yorgey
-
Conor McBride
-
Dan Doel
-
Eugene Kirpichov
-
Jonathan Cast
-
Martijn van Steenbergen
-
Matthew Brecknell
-
Robin Green
-
Ross Paterson