I plan to showcase an example of the power of typeclasses in a small intro I'll give to Haskell tomorrow.

I thought I'd double check on what I was going to present because I'm not 100% confident.

So, let's say I have two functions:

```
firstSort :: Int -> Int -> Ordering
firstSort a b = compare (even a) (even b)

secondSort :: Int -> Int -> Ordering
secondSort = compare

```

Now, I can combine those two sorts thanks to their Monoid instances:

```
sort :: Int -> Int -> Ordering
sort = firstSort <> secondSort

```

Now what I'd like to confirm is the process used during the `mappend` of the two sorts.

From what I understand, it works this way:

* first the instance:

```
instance Monoid b => Monoid (a -> b) where
        mempty _ = mempty
        mappend f g x = f x `mappend` g x

```

is used. This is done by instanciating the `a` of this instance with `(Int -> Int)`. Also, the declaration of `mappend` got me puzzled for some time since it takes 3 arguments instead of 2 but then I remembered that `(a -> b) -> (a -> b) -> (a -> b)` is actually the same as `(a -> b) -> (a -> b) -> a -> b`.

Thanks to this instance we obtain that `firstSort <> secondSort` is:

```
\a b -> (firstSort a b) <> (secondSort a b)

```
* then the instance:

```
instance Monoid Ordering where
        mempty         = EQ
        LT `mappend` _ = LT
        EQ `mappend` y = y
        GT `mappend` _ = GT

```

is used with the specified `mappend` on the results of `firstSort` and `secondSort`

So, to sum it up, it would match the `Monoid b => Monoid (a -> b)` instance with `b = Ordering` and `a = (Int -> Int)` and afterwards the `Monoid Ordering` instance.

Is that correct?