Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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 caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners