foundation icon indicating copy to clipboard operation
foundation copied to clipboard

Consider changing `id` to `identity`

Open seagreen opened this issue 9 years ago • 10 comments

This is bikeshedding so feel free to close it, but Protolude uses identity instead of id and I think it's a classy decision. The desire to use id as a variable name is pretty common. Also I feel like avoiding abbreviations in core function names is nice when possible (identity is still pretty short).

seagreen avatar Sep 10 '16 16:09 seagreen

I like the idea; not sure about my muscle memory though. anyone else like/dislike ?

vincenthz avatar Sep 10 '16 18:09 vincenthz

id shows up a lot in laws, but partly because of this I find it's actually pretty rare to use id in code - generally it can be removed by following one of those laws. In contrast, things having "id's" show up all the time. As a result, I think I'm slightly positive towards this proposal.

ndmitchell avatar Sep 10 '16 18:09 ndmitchell

The best bikeshed discussions are caused by non-contributors joining in, so here goes. Is identity optimal? There are other identity elements such as the additive identity of 0, multiplicative 1, and identity functors. Is idfun less ambiguous (though harder to guess)? (I like the idea of freeing up the name id.)

abooij avatar Sep 11 '16 11:09 abooij

Having a function identity would also be consistent with having a Monad Identity (like the one in Data.Functor.Identity). id can then be more easily used to denote identifiers (or anything else).

Is idfun less ambiguous (though harder to guess)?

I personally don't like specifying the type of a thing in its name.

JanGe avatar Sep 11 '16 15:09 JanGe

I think prioritising the function meaning for identity over the math (additive identity, ..) is suited to haskell being a _function_al language.

vincenthz avatar Sep 11 '16 15:09 vincenthz

All the other identities are identity with respect to some semantics, whereas the function identity really is identity for everything.

ndmitchell avatar Sep 11 '16 18:09 ndmitchell

How about noop? ;)

crabmusket avatar Sep 11 '16 23:09 crabmusket

@crabmusket: not that I think it doesn't have some charm, pushing toward cpu concept is a bit far fetch :)

Let's rename it to identity, I think everyone is in rough agreement (speak now otherwise)

vincenthz avatar Sep 14 '16 18:09 vincenthz

One thing, is that Control.Category.id is re-exported as id. We obviously can't change the name of the class without forking the class and creating some further compatibility issue. The alternative is to re-export with:

identity :: ...
identity = Control.Category.id

vincenthz avatar Sep 18 '16 06:09 vincenthz

Why not export identity :: a -> a, and leave id from Category not in scope by default, and now not clashing.

ndmitchell avatar Sep 18 '16 06:09 ndmitchell