3 ms·
Keep in mind that there are (infinitely) many ways to implement the identity function. One such example (in Haskell) is: foo = head . (:[]) This is the co
by chongli 14y ago
Keep in mind that there are (infinitely) many ways to implement the identity function. One such example (in Haskell) is:
foo = head . (:[])
This is the composition of putting an element into a list with removing it from the list. You can do this with any functor.
- FreeFull 14y agoWhich ultimately doesn't matter, because head . (:[]) doesn't behave differently from (\x -> x) no matter what the input is. The only possible variation on the id function is in how efficient it is, from fastest to never terminating.
- tmhedberg 14y ago> You can do this with any functor. Not to be pedantic, but being a functor has little to do with the fact that you can add and remove elements from lists. Knowing that a particular type is an instance of `Functor` tells you only one thing about that type: that you can `fmap` functions over its contents. But look at `fmap`'s type: fmap :: Functor f => (a -> b) -> f a -> f b There is no function with that type which can extract values from a functor, nor insert new ones. `fmap` can only modify the values already contained by the functor, leaving them in the container. Extraction of contained values from a wrapper and lifting/insertion of values into a wrapper require pattern matching and constructor application respectively, which means the type must have exposed constructors, a property independent of whether that type is a functor.