# Notes (HPFP 16/31): Functor

# 16 Functor

## 16.4 Let’s talk about 4, baby

### Excercises: Be Kind

`*`

`b`

is `* ->-> *``,`

T`is`

- `* -> * -> *`

## 16.7 Commonly used functors

### Exercises: Heavy Lifting

## 16.10 Exercises: Instances of Func

- Trivial doesn’t have anything inside it that fmap can apply a function to, fmap doesn’t make sense for things with kind
`*`

, or rather fmap on type constants is just function application, which is all f and no map.

- Trivial doesn’t have anything inside it that fmap can apply a function to, fmap doesn’t make sense for things with kind

## 16.11 Ignoring possibilities

### Exercise: Possibly

### Short Exercise

- The
`a`

in`First a`

might be a different type than the`b`

in`Second b`

. The function we pass to fmap can only operate on one of those types, but not both. In other words the function that fmap maps is of type`b -> c`

and kind`*`

. Furthermore, we have to apply the function to`Second b`

rather than`First a`

, because the structure that fmaps maps onto is of kind `*->*`. Our structure is`

(Sum a)`because`

Sum`is of kind`

* -> * -> *`and it needs to have accepted every type constructor but the last before its something that fmap can work on. But that doesn't mean we're barred from writing another function that does something different to`

Sum`, but something different wont be fmap.

## 16.7 Chapter Exercises

Determine if a valid Functor can be written for the datatype provided:

- No, Bool has kind
`*`

but fmap only works on `* -> *` - Yes, note that
`False'`

and`True'`

both take the same type`a`

- Yes, fmap can ignore
`Falsish`

- Yes… but why…
- Nope, theres nothing to fmap over, kind
`*`

Rearrange the arguments:

## 16.19 Follow-up resources

- Haskell Wikibook; The Functor class.
- Mark P. Jones; A system of constructor classes: overloading and implicit higher-order polymorphism.
- Gabriel Gonzalez; The functor design pattern.