Funny Story, Bro!

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import Control.Comonad         -- http://lpaste.net/107661

-- This is a solution for http://lpaste.net/107652

data Id a = Id a
   deriving Show

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

instance Comonad Id where
   extract (Id a) = a
   duplicate x = Id x

{--

extract [1,2,3] ~> 1
[1,2,3] =>> extract ~> [1,2,3]
[1,2,3] =>> id ~> [[1,2,3], [2,3], [3]]

extract (Id "quux") ~> "quux"
Id "foo" =>> extract ~> Id "foo"
Id "bar" =>> id ~> Id (Id "bar")

yup, all that happened at the listener

but, ... funny story, bro, here is what I typed at the listener:

*Main> id "bar" =>> id
["bar","ar","r"]

Do you see my capitalization mistake? That made all the difference!

When I did capitalize correctly, here's what I got:

*Main> Id "bar" =>> id
Id (Id "bar")

YAY!

 --}
13:4: Error: Eta reduce
Found:
duplicate x = Id x
Why not:
duplicate = Id