Define `id` using dot notation
The exact version id
- it's ... good id
. id
is often taken as a fundamental operator in pointless constructions, a kind of primitive on which more combinators are built.
If you really want, you can recover id
from other more complex operators, for example. using an instance Monad ((->) a)
:
id = join const
or an Applicative ((->) a)
instance
id = const <*> const
(in combinatorial logic, this I = S K K
, since <*>
there is S
also const
is K
)
Nothing could be easier than id
.
source to share
This question is interesting, because it id
is essentially the identity of any mathematical group of functions included in the composition. Simply put, when you get two opposite functions and compose them, you get id
.
So any of them will work polymorphically and in exactly the same way, although naturally slower:
id :: a -> a ---------------------------- id = snd . (0,) id = fst . (,0) id = (!! 0) . return id = ($ 0) . const id = (\(Just n) -> n) . Just
Or we could write this in a simple lambda expression, which is good practice and very simple:
id = \a -> a
This is all in a dotless style, which should be satisfying for your question, but it is not just dotless, but glasses free. All of these solutions may seem very valid, but they are not equivalent id
. These solutions, apart from the latter, create and deconstruct data structures that are expensive in terms of performance. Glasses-free style may be good practice, but not everywhere.
source to share