Re: Function Reference Issues

"Sebastien Mondet [email protected] [ocaml_beginners]" <[email protected]>
Newsgroups gmane.comp.lang.ocaml.beginners
Message-ID <CALScVYnffP_rYtbErGV3DBmgvOsK0B_Tuu7-vLeX4qE+k-bSQg@mail.gmail.com>
A “top-level” reference should not contain things with unbound type
variables (in a module declaration).

let my_func   obj  = assert false
has type  'a -> 'b   (→ 2 type variables)

If you want that reference you should force a "final" type, like:

let my_func_ref : (int -> unit) ref = ref my_func






On Thu, Jun 25, 2015 at 12:12 PM, Kenneth Miller
[email protected] [ocaml_beginners]
<[email protected]> wrote:
>
>
> I have some let definitions binding some functions to function references.
> This works nicely, but the typing system is giving me some hell about "type
> variables that cannot be generalized"; in my edits to the to promote the
> list type to a Core list, I have to provide type parameters the module
> constructors. This works fine so far, but now I have to have a declared
> reference that can be updated; it seems that I can't declare it raw,
> however:
>
> let my_func   obj  = assert false
>
>
> ...
>
> let my_func    = ref my_func
>
> At the rebinding, let my_func becomes a type issue with:
>
> Error: The type of this expression, (<type> -> <type>) ref,
>        contains type variables that cannot be generalized
>
> I don't know how to just get the compiler to accept that my_func is a
> function reference, and to allow it's declaration. Literally I can't do
> anything regarding just adding a () parameter, because then I'm not binding
> a value, I'm binding the function that returns a reference; you can't update
> that, because the function reference returned in each of the implementing
> modules that edit these such references is local to that executing
> scope-it's not the reference instance we want.
>
> How can I either get the compiler to accept such a function reference?
>
>
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.