caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] "Type constructor b would escape its scope"
@ 2016-03-27  6:19 Gregory Malecha
  2016-03-27  7:04 ` Leo White
  0 siblings, 1 reply; 10+ messages in thread
From: Gregory Malecha @ 2016-03-27  6:19 UTC (permalink / raw)
  To: caml users

[-- Attachment #1: Type: text/plain, Size: 2652 bytes --]

Hello --

I've encountered a typing error that I'm not sure how to track down. I
assume that what I'm doing is running up against the limitations of the
type system, so I assume there is some technical detail that I am missing.
Here's my problem:

I have defined the following type:

(* essentially the eliminator for lists *)
type ('a,'b) result_stream =
  ('a -> ('a,'b) result_stream -> 'b) ->
  (unit -> 'b) -> 'b

(* I have the following function, which seems to type check *)
let stream_declarations (type a)
: (internal_result,a) result_stream = ...

(* I am unable to implement this function *)
let generic_search_stream (type b) (glnumopt : int option)
: (internal_result, b) result_stream =
  stream_declarations

Ocaml complains with the following error message:

Error: This expression has type
         (internal_result, b) result_stream =
           (internal_result -> (internal_result, b) result_stream -> b) ->
           (unit -> b) -> b
       but an expression was expected of type
         (internal_result, b) result_stream =
           (internal_result -> (internal_result, b) result_stream -> b) ->
           (unit -> b) -> b
       The type constructor b would escape its scope

Since the types match up exactly, I can only assume that this has something
to do with the type declaration (type b) but I can't see what is wrong. My
expectation is that the scope of [b] ends at the end of the
[generic_search_stream] function and is used as the type parameter to
[stream_declarations], this seems to not be the case though.

Wondering if OCaml requires arguments in order to instantiate polymorphic
functions, I tried to eta-expand the definition as follows:

let generic_search_stream (type b) (glnumopt : int option)
: (internal_result, b) result_stream =
  fun cons nil -> stream_declarations cons nil

With this code, the "error" is with 'cons' and says:

Error: This expression has type
         internal_result -> (internal_result, b) result_stream -> b
       but an expression was expected of type
         internal_result -> (internal_result, b) result_stream -> b
       Type
         (internal_result, b) result_stream =
           (internal_result -> (internal_result, b) result_stream -> b) ->
           (unit -> b) -> b
       is not compatible with type
         (internal_result, b) result_stream =
           (internal_result -> (internal_result, b) result_stream -> b) ->
           (unit -> b) -> b
       The type constructor b would escape its scope

Essentially the same error, but it doesn't seem to lead me to any potential
solutions.

Can someone explain this error to me?

Thanks.

-- 
gregory malecha

[-- Attachment #2: Type: text/html, Size: 5753 bytes --]

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

end of thread, other threads:[~2016-03-28 21:00 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-27  6:19 [Caml-list] "Type constructor b would escape its scope" Gregory Malecha
2016-03-27  7:04 ` Leo White
2016-03-27 18:52   ` Gregory Malecha
2016-03-28  1:12     ` Jacques Garrigue
2016-03-28  4:20       ` Gregory Malecha
2016-03-28  8:07         ` Gabriel Scherer
2016-03-28 15:35           ` Gregory Malecha
2016-03-28 19:20           ` Arnaud Spiwack
2016-03-28 20:51             ` Leo White
2016-03-28 21:00             ` Gerd Stolpmann

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