caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Andre Nathan <andre@digirati.com.br>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Segfault with open GADTs
Date: Tue, 18 Oct 2016 12:50:45 -0200	[thread overview]
Message-ID: <0ee74760-8b24-66bd-2b5c-900df67e220a@digirati.com.br> (raw)
In-Reply-To: <20161018142102.GA21704@frosties>


[-- Attachment #1.1: Type: text/plain, Size: 810 bytes --]

On 10/18/2016 12:21 PM, Goswin von Brederlow wrote:
> You can pass along the outermost to_string to all to_string
> functions so they can restart from the outside when they recurse.

Yep :) For the record, I got it working like this:

In M0:

  let assert_false _ = assert false
  type f = { f : 'a. 'a t -> string }

  let rec to_string
      : type a b. ?f:f -> a t -> string
      = fun ?(f = { f = assert_false }) e -> match e with
      | I i -> "I:" ^ string_of_int i
      | S s -> "S:" ^ s
      | P (x, y) -> to_string ~f x ^ to_string ~f y
      | e -> f.f e

In M1:

    let rec to_string' : type a. a t -> string = function
      | T t -> to_string ~f:{ f = to_string' } t
      | x -> to_string ~f:{ f = to_string' } x

    let to_string = to_string'

Cheers,
Andre


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

  reply	other threads:[~2016-10-18 14:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-18 12:47 Andre Nathan
2016-10-18 13:10 ` Pierrick Couderc
2016-10-18 13:52   ` Andre Nathan
2016-10-18 14:21     ` Goswin von Brederlow
2016-10-18 14:50       ` Andre Nathan [this message]
2016-10-18 13:16 ` Jeremy Yallop

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=0ee74760-8b24-66bd-2b5c-900df67e220a@digirati.com.br \
    --to=andre@digirati.com.br \
    --cc=caml-list@inria.fr \
    /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;
as well as URLs for NNTP newsgroup(s).