From: mandrykin <mandrykin@ispras.ru>
To: Oleg <oleg@okmij.org>, edwin+ml-ocaml@etorok.net, caml-list@inria.fr
Cc: caml-list-request@inria.fr
Subject: Re: [Caml-list] Clever typing for client-server communication?
Date: Sat, 25 Jul 2015 18:55:12 +0300 [thread overview]
Message-ID: <00260dc5e1bf970e84ccc99948acea6d@ispras.ru> (raw)
In-Reply-To: <20150725124250.GA2259@Magus.sf-private>
> This is probably a folklore, but it was mentioned on this list more
> than
> a decade ago by Jacques Garrigue. We have used this trick extensively
> in
>
> http://okmij.org/ftp/meta-programming/HPC.html#GE-generation
>
For me actually knowing the trick used in the paper alone was not enough
to quickly come up with this solution. I had already used this object
constraints several times in even in real-life code, but that didn't
help much(. To me the key idea here (in the Jeremy Yallop's solution) is
the ability to express the "negation" function on type level with a pair
of mutually-recursive types and a constraint. This can actually be also
done with polymorphic variants instead of object types:
type client = [`cs of server * [`client]]
and server = [`cs of client * [`server]]
type 'a rev = 'b constraint 'a = [`cs of 'b * _] (* rev is the function
*)
This ensures the relations client rev = server, server rev = client and
client <> server. This approach seems powerful enough to express any
finite permutation group, e.g. for 2 elements:
type z = [`t of [`e1] * [`e2] * z] (* initial permutation *)
type 'e e1 = [`t of 'e1 * 'e2 * 'e e1] (* neutral permutation *)
constraint 'e = [`t of 'e1 * 'e2 * _ ]
and 'e e2 = [`t of 'e2 * 'e1 * 'e e2] (* reverse permutation *)
constraint 'e = [`t of 'e1 * 'e2 * _]
type 'a inv = 'b constraint 'a = [`t of _ * _ * 'b]
Here "-e1 - e2 - e3 - ... - en + e1' + e2' + ... + em'" (using `+' for
the group operation and `-' for the inverse) can be encoded as "z e1 e2
... en inv e1' e2' ... em'". By Cayley's theorem (states that every
finite group G is isomorphic to a subgroup of the symmetric group acting
on G) this means (if I got it right) that in fact any finite group
operation (and the corresponding inverse) is encodiable in OCaml as
type-level function!
Regards,
Mikhail
next prev parent reply other threads:[~2015-07-25 15:55 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-24 11:01 Markus Weißmann
2015-07-24 11:20 ` Nicolas Ojeda Bar
2015-07-24 18:41 ` Mikhail Mandrykin
2015-07-24 20:23 ` octachron
2015-07-24 20:25 ` Jeremy Yallop
2015-07-24 20:57 ` Török Edwin
2015-07-25 12:42 ` Oleg
2015-07-25 15:55 ` mandrykin [this message]
2015-08-08 21:39 ` Markus Mottl
2015-08-09 13:04 ` Jacques Garrigue
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=00260dc5e1bf970e84ccc99948acea6d@ispras.ru \
--to=mandrykin@ispras.ru \
--cc=caml-list-request@inria.fr \
--cc=caml-list@inria.fr \
--cc=edwin+ml-ocaml@etorok.net \
--cc=oleg@okmij.org \
/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