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: skaller <skaller@u...>
Subject: Re: [Caml-list] Suggestion: Pervasives.identity
On Sat, 2004-04-24 at 01:48, Brian Hurt wrote:
> On Fri, 23 Apr 2004, Martin Jambon wrote:
> > 
> > In the same style, we already have Pervasives.ignore, so why not
> > Pervasives.identity?

> Possibly stupid question: what use would this function be?

I use it with higher order functions. For example 
I have a function:

	type typed_expr = expr_t * type_t
	map_typed_expr:
		(expr_t -> expr_t) ->
		(type_t -> type_t) ->
		typed_expr_t -> typed_expr_t

Sometimes I wish to map only the typing in an expression,
and sometimes only the expression terms not the typing.
So I pass 'identity' as one of the arguments.

An identity function would also be useful in machine
generated code in a situation similar to the above
where the HOF was implemented in the code generator,
and you don't want to specialise the generator
but would rather the target compiler optimise
the application of 'identity' away.

So it is 'useful' -- but this is no argument
it should be in Pervasives.

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net



-------------------
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