Skip to content

Commit 858296b

Browse files
committed
discuss :k Functor
1 parent 907853f commit 858296b

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

source_md/making-our-own-types-and-typeclasses.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,6 +1811,22 @@ ghci> :k Either String Int
18111811
Either String Int :: *
18121812
```
18131813

1814+
What if we do something crazy and ask what the kind is of something entirely different, like a type class?
1815+
1816+
```{.haskell:hs}
1817+
ghci> :k Functor
1818+
Functor :: (* -> *) -> Constraint
1819+
```
1820+
1821+
Woot, that works!
1822+
We see two new things here.
1823+
First, `Constraint` is the kind of constraints, i.e. the things that appear to the left of the `=>` in type signatures.
1824+
The `Ord Int` instance, for instance, has kind `Constraint`.
1825+
1826+
We also see that, whereas `Maybe` and `Either` take concrete types as arguments, `Functor` does not.
1827+
Instead of a concrete type, it takes something that *itself* takes a single concrete type as an argument.
1828+
So it can take `Maybe`, which has kind `* -> *`, but it will not take `Char`, as its kind is merely `*`.
1829+
18141830
When we wanted to make `Either` a part of the `Functor` typeclass, we had to partially apply it because `Functor` wants types that take only one parameter while `Either` takes two.
18151831
In other words, `Functor` wants types of kind `* -> *` and so we had to partially apply `Either` to get a type of kind `* -> *` instead of its original kind `* -> * -> *`.
18161832
If we look at the definition of `Functor` again

0 commit comments

Comments
 (0)