Skip to content

Commit

Permalink
Monomorphize compare function for builtin types
Browse files Browse the repository at this point in the history
The `[%ord: int]` expression expands to `Pervasives.compare`.
Since this function is polymorphic, it may be used with other types.
For example, the following expression typechecks:

```.ocaml
([%ord: int] : string -> string -> int)
```

This adds a type constraint on the `Pervasives.compare` call so that it becomes
monomorphic. This is also more consistent with how this case is handled in the
`eq` plugin.
  • Loading branch information
emillon committed Sep 26, 2016
1 parent c9e69b2 commit d5fe215
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src_plugins/ppx_deriving_ord.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ and expr_of_typ quoter typ =
| [%type: int64] | [%type: Int64.t] | [%type: nativeint]
| [%type: Nativeint.t] | [%type: float] | [%type: bool]
| [%type: char] | [%type: string] | [%type: bytes]) ->
[%expr Pervasives.compare]
let compare_fn = [%expr fun (a:[%t typ]) b -> Pervasives.compare a b] in
Ppx_deriving.quote quoter compare_fn
| true, [%type: [%t? typ] ref] ->
[%expr fun a b -> [%e expr_of_typ typ] !a !b]
| true, [%type: [%t? typ] list] ->
Expand Down

0 comments on commit d5fe215

Please sign in to comment.