caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Comparison of functional values
@ 2001-03-06 21:51 Olivier Andrieu
  2001-03-07  5:20 ` Alan Schmitt
  0 siblings, 1 reply; 6+ messages in thread
From: Olivier Andrieu @ 2001-03-06 21:51 UTC (permalink / raw)
  To: caml-list


Hello list, 

I wanted to build a Set of functional value. But generic equality
can't be used for functional values (raises an exception ...). It is
therefore difficult to build a Set of such values because the Set.Make
functor requires a comparison function and Pervasives.compare relies
on (=).

Is there a way around this ? I thought I could use physical equality
(wich is OK wrt functional values) but there's no such thing as
`physical inequality'.

-- 
Olivier Andrieu
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 6+ messages in thread

* (no subject)
@ 2001-03-06 22:08   ` Juergen Pfitzenmaier
  2001-03-07  8:49     ` [Caml-list] Comparison of functional values Olivier Andrieu
  0 siblings, 1 reply; 6+ messages in thread
From: Juergen Pfitzenmaier @ 2001-03-06 22:08 UTC (permalink / raw)


Olivier Andrieu wanted to build a Set of functional values but had problems
with the comparison of these values.

One solution would be to have a Set of pairs. The first element would be a
functional value and the second something of a simple type (like integer).
Then you define your comparison function only to use this second element.
The only inconvenience is that you have always to select explicitly the first
element of such pairs to get the functional value; but you can hide this
inside a module build around Set.
hope this is of some help

pfitzen

-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] Comparison of functional values
  2001-03-06 21:51 [Caml-list] Comparison of functional values Olivier Andrieu
@ 2001-03-07  5:20 ` Alan Schmitt
  2001-03-06 22:08   ` Juergen Pfitzenmaier
  0 siblings, 1 reply; 6+ messages in thread
From: Alan Schmitt @ 2001-03-07  5:20 UTC (permalink / raw)
  To: Olivier Andrieu; +Cc: caml-list

>Is there a way around this ? I thought I could use physical equality
>(wich is OK wrt functional values) but there's no such thing as
>`physical inequality'.
>

As stated in http://caml.inria.fr/ocaml/htmlman/manual031.html, != is
the negation of ==.

Alan Schmitt

--
The hacker: someone who figured things out and made something cool happen.
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] Comparison of functional values
  2001-03-06 22:08   ` Juergen Pfitzenmaier
@ 2001-03-07  8:49     ` Olivier Andrieu
  2001-03-07  8:56       ` Xavier Leroy
  0 siblings, 1 reply; 6+ messages in thread
From: Olivier Andrieu @ 2001-03-07  8:49 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: caml-list, Juergen Pfitzenmaier

 Alan Schmitt [Wednesday 7 March 2001] :
 > As stated in http://caml.inria.fr/ocaml/htmlman/manual031.html, != is
 > the negation of ==.

Salut Alan !

I known. But to use the Set functor, you need a `compare' function of
type ('a -> 'a -> int) whereas != and == have type ('a -> bool). 
So != does not seem very helpful here.

What I meant actually, was a «physical compare». I found out that 
this (crude) C function works :

value phys_comp(value a, value b)
{
 if(a<b)
   return Val_int(-1) ;
 else if(a>b)
   return Val_int(+1) ;
 else 
   return Val_int(0);
}

Olivier
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] Comparison of functional values
  2001-03-07  8:49     ` [Caml-list] Comparison of functional values Olivier Andrieu
@ 2001-03-07  8:56       ` Xavier Leroy
  0 siblings, 0 replies; 6+ messages in thread
From: Xavier Leroy @ 2001-03-07  8:56 UTC (permalink / raw)
  To: Olivier Andrieu; +Cc: Alan Schmitt, caml-list, Juergen Pfitzenmaier

> What I meant actually, was a «physical compare». I found out that 
> this (crude) C function works :
> 
> value phys_comp(value a, value b)
> {
>  if(a<b)
>    return Val_int(-1) ;
>  else if(a>b)
>    return Val_int(+1) ;
>  else 
>    return Val_int(0);
> }

No, it does not:  the GC can copy heap blocks and change the relative
ordering of their memory addresses.  You really need to pair your
functions with unique identifying integers.

- Xavier Leroy
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] Comparison of functional values
@ 2001-03-06 22:17 Arturo Borquez
  0 siblings, 0 replies; 6+ messages in thread
From: Arturo Borquez @ 2001-03-06 22:17 UTC (permalink / raw)
  To: andrieu; +Cc: caml-list

On Tue, 06 March 2001, Olivier Andrieu wrote:

> 
> 
> Hello list, 
> 
> I wanted to build a Set of functional value. But generic equality
> can't be used for functional values (raises an exception ...). It is
> therefore difficult to build a Set of such values because the Set.Make
> functor requires a comparison function and Pervasives.compare relies
> on (=).
> 
> Is there a way around this ? I thought I could use physical equality
> (wich is OK wrt functional values) but there's no such thing as
> `physical inequality'.
> 
> -- 
> Olivier Andrieu
> -------------------
> To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr

Hi Olivier:
Perhaps this help

let a = fun f x -> x = x;;
let b = fun f x -> x = x;;
(a == b) = true;;
-: bool = false
not (a == b) = true;;
-: bool = true

Regards
Arturo Borquez


Find the best deals on the web at AltaVista Shopping!
http://www.shopping.altavista.com
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2001-03-07  8:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-06 21:51 [Caml-list] Comparison of functional values Olivier Andrieu
2001-03-07  5:20 ` Alan Schmitt
2001-03-06 22:08   ` Juergen Pfitzenmaier
2001-03-07  8:49     ` [Caml-list] Comparison of functional values Olivier Andrieu
2001-03-07  8:56       ` Xavier Leroy
2001-03-06 22:17 Arturo Borquez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).