The bag of gold at the end of the rainbow

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import Data.Bag             -- http://lpaste.net/107806 for the bonus
import Control.Comonad      -- http://lpaste.net/107661 for the bonus

{--

Okay so you saw from today's exercise at http://lpaste.net/107878 that P36
has the signature of:

groupedPrimeFactors :: Integer -> [(Integer, Int)]

That's one way of grouping the prime factors into groups ...

-- or ... BONUS! --------------------------------------------------------

Another way is to use the 'Bag' or 'MultiSet' data type. 'Bag' is from
anon. 'MultiSet' is a nonesensical word from more recent times from those too
embarrassed to used the word 'bag' in a sentence, so they say the word 
'multiset,' which means a set of unique objects with a count for each unique
object that is ... repeated ... in the set.

You see the absurdity? A set contains unique objects, but a multi-set contains
multiple unique objects. So are these unique objects unique? No, of course not,
as there are multiples of them, so it's either not a set (because the objects
are not unique) or the objects are not unique in the set (which, by definition,
contains only unique objects).

... 'MultiSet.' Yeah.

Whatever.

But we CAN'T say the word 'bag' because that's derogatory somehow, so, instead,
we say an absurdity ('MultiSet') because we don't want to look like fools
saying the word 'bag.'

We just want to say absurities, but give them multi-syllabic renderings, so we
look sophisticated saying these absurdities.

The bonus was to survive my rant.

The bonus-bonus is to create the bag data type in module Data.Bag and have 
that as the result of a prime factor function: --}

baggedPrimeFactors :: Integer -> Bag Integer
baggedPrimeFactors n = undefined

{--

And then, bonus-bonus-bonus: make Bag a a Functor instance then a Comonad...

Some people think functionally in bananas, barbed-wire and brackets; however, 
I think in Arrows, Monads and Comonads. Also make it a monoid, just because
it is, as I see it.

I still have not figured out how to make Bag a a monad, however, as I run
into trouble with bind around Ord b. Any thoughts on how to make Bag a a
monad instance?

 --}