[CakeML-dev] Adding polymorphic compare to CakeML

Scott Owens S.A.Owens at kent.ac.uk
Mon Nov 28 23:29:05 UTC 2016


So, what would the source semantics do for values that contain refs or closures? I suppose that closures can always return 0, to be compatible with =, but what about references? In OCaml, compare traverses the references, as does =. But our = does a pointer comparison on refs, and we probably want compare to do so as well, but we can’t do < on the pointer since the GC can move them. We could go back to raising exceptions, but then compare can’t use the quick pointer equality check as an optimisation for non-references.

Scott

> On 2016/11/28, at 23:17, Magnus Myreen <magnus.myreen at gmail.com> wrote:
> 
> Hi all,
> 
> I'm currently re-implementing recursive equality in wordLang.
> 
> It occurred to me that it's easy to add support for something
> similar to OCaml's polymorphic compare function. Example:
> 
>    # compare;;
>    - : 'a -> 'a -> int = <fun>
>    # compare 0 1;;
>    - : int = -1
>    # compare 0 2;;
>    - : int = -1
>    # compare 1 1;;
>    - : int = 0
>    # compare 2 1;;
>    - : int = 1
>    # compare 3 1;;
>    - : int = 1
> 
> The CakeML semantics of this primitive would be pretty clean for
> values that do not contain closures or references.
> 
> If no one is against having compare in CakeML, then I'll add it to BVL
> and downwards. I would need help in propagating it all the way to the
> source semantics.
> 
> Cheers,
> Magnus
> 
> _______________________________________________
> Developers mailing list
> Developers at cakeml.org
> https://lists.cakeml.org/listinfo/developers



More information about the Developers mailing list