Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Suggestion: Pervasives.identity
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-04-23 (12:56)
From: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [Caml-list] Suggestion: Pervasives.identity
> Is there a good why there is no predefined identity function?

A good reason, yes: it's generally useless.  There are no predefined S
and K combinators either :-)

> (fun x -> x) is sometimes less readable, and seems to be not
> compiled (yet?) as this black magic:
> external identity : 'a -> 'a : "%identity"

Even if you define
        external identity: 'a -> 'a = "%identity"
references to "identity" will be compiled like "fun x -> x".
It's only direct applications of "identity", e.g. "identity 3", that
would be more efficient than with the definition
        let identity x = x
But I hope your programs don't contain calls like "identity x"...

> In the same style, we already have Pervasives.ignore, so why not
> Pervasives.identity?

Because Pervasives.ignore is very useful and commonly used to deal
with the "should have type unit" warning.

- Xavier Leroy

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: