caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] problem with generalisation
@ 2017-09-23 17:47 Christophe Raffalli
  2017-09-23 20:40 ` Damien Guichard
  2017-09-23 21:04 ` Markus Mottl
  0 siblings, 2 replies; 3+ messages in thread
From: Christophe Raffalli @ 2017-09-23 17:47 UTC (permalink / raw)
  To: caml-list

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

Hello,

I am blocked by this case not working (I reported on Mantis ...
https://caml.inria.fr/mantis/view.php?id=7636)

Any hint on how to make it works, apart fomr Obj.magic ?

I can not change the types, they come from a functor.

====================================================
type ('a, 'b) elt = 'a

type 'a iter = { f : 'b.('a, 'b) elt -> unit }

let promote f : 'a -> unit =
  let f : 'b.('a, 'b) elt -> unit = fun x -> f x in
    { f }
====================================================

Cheers,
Christophe

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [Caml-list] problem with generalisation
  2017-09-23 17:47 [Caml-list] problem with generalisation Christophe Raffalli
@ 2017-09-23 20:40 ` Damien Guichard
  2017-09-23 21:04 ` Markus Mottl
  1 sibling, 0 replies; 3+ messages in thread
From: Damien Guichard @ 2017-09-23 20:40 UTC (permalink / raw)
  To: caml-list


Hi Christophe,

Given the types, the only thing i can do is to promote an iterator :

let promote i = {f = fun x -> i.f x}

I can't do anything else and i eagerly wait the whole scholar answer.

Regards,

- Damien Guichard


Christophe Raffalli a écrit :
> Hello,
>
> I am blocked by this case not working (I reported on Mantis ...
> https://caml.inria.fr/mantis/view.php?id=7636)
>
> Any hint on how to make it works, apart fomr Obj.magic ?
>
> I can not change the types, they come from a functor.
>
> ====================================================
> type ('a, 'b) elt = 'a
>
> type 'a iter = { f : 'b.('a, 'b) elt -> unit }
>
> let promote f : 'a -> unit =
>    let f : 'b.('a, 'b) elt -> unit = fun x -> f x in
>      { f }
> ====================================================
>
> Cheers,
> Christophe


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

* Re: [Caml-list] problem with generalisation
  2017-09-23 17:47 [Caml-list] problem with generalisation Christophe Raffalli
  2017-09-23 20:40 ` Damien Guichard
@ 2017-09-23 21:04 ` Markus Mottl
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Mottl @ 2017-09-23 21:04 UTC (permalink / raw)
  To: Christophe Raffalli; +Cc: caml-list

Hi Christophe,

the following definition of "promote" works for me:

  let promote (type a) (f : a -> unit) : a iter = { f }

It seems that making the type variable locally existential within the
body of "promote" helps the compiler make the correct inference.
Using a universally quantified 'a instead won't work.

Regards,
Markus

On Sat, Sep 23, 2017 at 1:47 PM, Christophe Raffalli
<christophe@raffalli.eu> wrote:
> Hello,
>
> I am blocked by this case not working (I reported on Mantis ...
> https://caml.inria.fr/mantis/view.php?id=7636)
>
> Any hint on how to make it works, apart fomr Obj.magic ?
>
> I can not change the types, they come from a functor.
>
> ====================================================
> type ('a, 'b) elt = 'a
>
> type 'a iter = { f : 'b.('a, 'b) elt -> unit }
>
> let promote f : 'a -> unit =
>   let f : 'b.('a, 'b) elt -> unit = fun x -> f x in
>     { f }
> ====================================================
>
> Cheers,
> Christophe



-- 
Markus Mottl        http://www.ocaml.info        markus.mottl@gmail.com

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

end of thread, other threads:[~2017-09-23 21:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-23 17:47 [Caml-list] problem with generalisation Christophe Raffalli
2017-09-23 20:40 ` Damien Guichard
2017-09-23 21:04 ` Markus Mottl

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