From: Leo White <lpw25@cam.ac.uk>
To: Erkki Seppala <flux@modeemi.cs.tut.fi>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Recursive fixed polymorphic variants
Date: Tue, 28 May 2013 09:20:04 +0100 [thread overview]
Message-ID: <86ehcrfrd7.fsf@cam.ac.uk> (raw)
In-Reply-To: <m49txlnpq48.fsf@coffee.modeemi.fi> (Erkki Seppala's message of "Tue, 28 May 2013 09:36:55 +0300")
> let rec f = function `B x -> g x | `A -> ()
> and g = function `B x -> f x | `A -> ();;
>
> # f (M.b (M.a ()))
> - : unit = ()
>
> This gives f (and g) the inferred type ([< `A | `B of [< `A | `B of 'a
> ] ] as 'a) -> unit.
>
> I was under the impression I should be able to describe using the type
> variable syntax in function type, but I was unable to.
Note that you can use polymorphic recursion to give f a very similar
type that also works for this particular example:
# let rec f : 'a. ([< `A | `B of ([< `A | `B of 'b ] as 'b) ] as 'a) -> unit =
function `B x -> f x | `A -> ();;
val f : [< `A | `B of [< `A | `B of 'a ] as 'a ] -> unit = <fun>
# f (M.b (M.a ()));;
- : unit = ()
Regards,
Leo
next prev parent reply other threads:[~2013-05-28 8:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-27 16:30 Jacques-Pascal Deplaix
2013-05-28 6:36 ` Erkki Seppala
2013-05-28 8:20 ` Leo White [this message]
2013-05-28 8:13 ` Leo White
2013-05-28 21:01 ` Jacques-Pascal Deplaix
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=86ehcrfrd7.fsf@cam.ac.uk \
--to=lpw25@cam.ac.uk \
--cc=caml-list@yquem.inria.fr \
--cc=flux@modeemi.cs.tut.fi \
/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