caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: [Caml-list] typing question: universal type variable in class type
@ 2016-06-24 19:09 Hongbo Zhang (BLOOMBERG/ 731 LEX)
  0 siblings, 0 replies; 3+ messages in thread
From: Hongbo Zhang (BLOOMBERG/ 731 LEX) @ 2016-06-24 19:09 UTC (permalink / raw)
  To: yallop; +Cc: caml-list

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

Hi Jeremy, 
   Thanks for the reference! 
   The work around is a bit complex since this part is FFI code, so we may fall back to use an abstract type `'a promise` instead.
   In your comments "In an imaginary extension to OCaml
with support for groups of mutually-recursive types and classes we
could write something like this:

class ['a] container (v:'a) = object
method map : 'b. ('a -> 'b) -> 'b container_aux =
fun f -> { container = new container (f v) }
end
and 'a container_aux = { container: 'a container }", this is a nice feature I wish we could have in OCaml -- Hongbo

From: yallop@gmail.com At: 06/24/16 14:56:35
To: HONGBO ZHANG (BLOOMBERG/ 731 LEX)
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] typing question: universal type variable in class type

On 24 June 2016 at 19:22, Hongbo Zhang (BLOOMBERG/ 731 LEX)
<hzhang295@bloomberg.net> wrote:
> When we wrote bindings for promise, we want to express things (simplified )
> like below:
>
> class type ['b] promise = object
> method then_ : 'a . ('b -> 'a promise) -> 'a promise
> end
>
> It is not expressible in OCaml, The universal type variable 'a can not be
> generalized, I tried this too:
>
> type 'b promise = < then_ : 'a . ('b -> 'a u) -> 'a u >
>
> It does not work either, thanks -- Hongbo

You might find something useful in this thread:

   https://sympa.inria.fr/sympa/arc/caml-list/2015-10/msg00130.html

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



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

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

* Re: [Caml-list] typing question: universal type variable in class type
  2016-06-24 18:22 Hongbo Zhang (BLOOMBERG/ 731 LEX)
@ 2016-06-24 18:55 ` Jeremy Yallop
  0 siblings, 0 replies; 3+ messages in thread
From: Jeremy Yallop @ 2016-06-24 18:55 UTC (permalink / raw)
  To: Hongbo Zhang; +Cc: Caml List

On 24 June 2016 at 19:22, Hongbo Zhang (BLOOMBERG/ 731 LEX)
<hzhang295@bloomberg.net> wrote:
> When we wrote bindings for promise, we want to express things (simplified )
> like below:
>
> class type ['b] promise = object
> method then_ : 'a . ('b -> 'a promise) -> 'a promise
> end
>
> It is not expressible in OCaml, The universal type variable 'a can not be
> generalized, I tried this too:
>
> type 'b promise = < then_ : 'a . ('b -> 'a u) -> 'a u >
>
> It does not work either, thanks -- Hongbo

You might find something useful in this thread:

   https://sympa.inria.fr/sympa/arc/caml-list/2015-10/msg00130.html

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

* [Caml-list] typing question: universal type variable in class type
@ 2016-06-24 18:22 Hongbo Zhang (BLOOMBERG/ 731 LEX)
  2016-06-24 18:55 ` Jeremy Yallop
  0 siblings, 1 reply; 3+ messages in thread
From: Hongbo Zhang (BLOOMBERG/ 731 LEX) @ 2016-06-24 18:22 UTC (permalink / raw)
  To: caml-list

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

Dear all,
     When we wrote bindings for promise, we want to express things (simplified ) like below:

class type ['b] promise = object
    method then_ : 'a . ('b -> 'a promise) -> 'a promise
end

It is not expressible in OCaml, The universal type variable 'a can not be generalized, I tried this too:

type 'b promise = < then_ : 'a . ('b ->  'a u) -> 'a u >

It does not work either, thanks -- Hongbo

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

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

end of thread, other threads:[~2016-06-24 19:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-24 19:09 [Caml-list] typing question: universal type variable in class type Hongbo Zhang (BLOOMBERG/ 731 LEX)
  -- strict thread matches above, loose matches on Subject: below --
2016-06-24 18:22 Hongbo Zhang (BLOOMBERG/ 731 LEX)
2016-06-24 18:55 ` Jeremy Yallop

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