From: Gregory Malecha <gmalecha@gmail.com>
To: caml users <caml-list@inria.fr>
Subject: [Caml-list] "Type constructor b would escape its scope"
Date: Sat, 26 Mar 2016 23:19:34 -0700 [thread overview]
Message-ID: <CAGraiHLc4w5s7+AYbkHfWKJ7agdrD4Zxuc5ptRT_hsTxjyUjbQ@mail.gmail.com> (raw)
[-- 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 --]
next reply other threads:[~2016-03-27 6:20 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-27 6:19 Gregory Malecha [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAGraiHLc4w5s7+AYbkHfWKJ7agdrD4Zxuc5ptRT_hsTxjyUjbQ@mail.gmail.com \
--to=gmalecha@gmail.com \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox