The monsters of the Id

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module Data.Id where

import Control.Comonad       -- http://lpaste.net/107661
import Control.Applicative

-- our Identity functor. Because I said so!

data Id a = Id a
   deriving (Eq, Show)

instance Functor Id where
   fmap f (Id a) = Id $ f a

instance Applicative Id where
   pure x = Id x
   Id f <*> Id a = Id $ f a

instance Monad Id where
   return x = Id x
   (Id a) >>= f = f a

instance Copointed Id where
   extract (Id a) = a

instance Comonad Id where
   duplicate idx = Id idx
15:4: Error: Eta reduce
Found:
pure x = Id x
Why not:
pure = Id
19:4: Error: Eta reduce
Found:
return x = Id x
Why not:
return = Id
26:4: Error: Eta reduce
Found:
duplicate idx = Id idx
Why not:
duplicate = Id