the-lambda-church/merlin — pull request #201 by gasche (2014-04-03 08:57:36+00:00)
Title: a better fix for the 4.00.1 + existential type issue

The source of the problem was the Locate case that instantiates the
GADT parameter with a polymorphic variant:

```ocaml
type _ request =
| ...
| Locate
: string * position option
-> [ `Found of string option * Lexing.position
| `Not_in_env of string
| `File_not_found of string
| `Not_found
] request
```

Instantiation of rigid variables with polymorphic variant was
ill-supported in 4.00.1 and improved in 4.01, hence the
backward-incompatibility of the code before the first fix. The first
fix adds annotation everywhere, at a strong cost in concision and
readability; it is in fact sufficient to avoid "opening" the
polymorphic variant in the pattern-matching that does the
GADT-instantiation.

git diff HEAD~2 now gives:

```diff
begin match request, response with
| ...
| Complete_prefix _, compl_list ->
`List (List.map json_of_completion compl_list)
- | Locate _, `Not_found ->
- `String "Not found"
- | Locate _, `Not_in_env str ->
- `String (Printf.sprintf "Not in environment '%s'" str)
- | Locate _, `File_not_found msg ->
- `String msg
- | Locate _, `Found (None,pos) ->
- `Assoc ["pos",pos_to_json pos]
- | Locate _, `Found (Some file,pos) ->
- `Assoc ["file",`String file; "pos",pos_to_json pos]
+ | Locate _, resp ->
+ begin match resp with
+ | `Not_found -> `String "Not found"
+ | `Not_in_env str ->
+ `String (Printf.sprintf "Not in environment '%s'" str)
+ | `File_not_found msg ->
+ `String msg
+ | `Found (None,pos) ->
+ `Assoc ["pos",pos_to_json pos]
+ | `Found (Some file,pos) ->
+ `Assoc ["file",`String file; "pos",pos_to_json pos]
+ end
| Drop, position -> pos_to_json position
| Seek _, position -> pos_to_json position
| Boundary _, Some {Location. loc_start; loc_end} ->
```