From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id DB6807F84F for ; Mon, 24 Feb 2014 14:48:34 +0100 (CET) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of puech@pps.univ-paris-diderot.fr) identity=pra; client-ip=194.254.61.138; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="puech@pps.univ-paris-diderot.fr"; x-sender="puech@pps.univ-paris-diderot.fr"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of puech@pps.univ-paris-diderot.fr) identity=mailfrom; client-ip=194.254.61.138; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="puech@pps.univ-paris-diderot.fr"; x-sender="puech@pps.univ-paris-diderot.fr"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@korolev.univ-paris7.fr) identity=helo; client-ip=194.254.61.138; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="puech@pps.univ-paris-diderot.fr"; x-sender="postmaster@korolev.univ-paris7.fr"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkgFAEtNC1PC/j2KWmdsb2JhbABZgmUhO8FEgRYWAwEXCRMTKoIlAQEFJwsBBUARCxgJFg8JAwIBAgExFBMIAogBAQMJxgoXjGiCAxaEIgSZZoUWjw0 X-IPAS-Result: AkgFAEtNC1PC/j2KWmdsb2JhbABZgmUhO8FEgRYWAwEXCRMTKoIlAQEFJwsBBUARCxgJFg8JAwIBAgExFBMIAogBAQMJxgoXjGiCAxaEIgSZZoUWjw0 X-IronPort-AV: E=Sophos;i="4.97,535,1389740400"; d="scan'208";a="50285926" Received: from korolev.univ-paris7.fr ([194.254.61.138]) by mail3-smtp-sop.national.inria.fr with ESMTP; 24 Feb 2014 14:48:34 +0100 Received: from potemkin.univ-paris7.fr (potemkin.univ-paris7.fr [IPv6:2001:660:3301:8000::1:1]) by korolev.univ-paris7.fr (8.14.4/8.14.4/relay1/46573) with ESMTP id s1ODmYPV005706 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Mon, 24 Feb 2014 14:48:34 +0100 Received: from mailhub.math.univ-paris-diderot.fr (mailhub.math.univ-paris-diderot.fr [81.194.30.253]) by potemkin.univ-paris7.fr (8.14.4/8.14.4/relay2/46573) with ESMTP id s1ODmY3n023365 for ; Mon, 24 Feb 2014 14:48:34 +0100 Received: from mailhub.math.univ-paris-diderot.fr (localhost [127.0.0.1]) by mailhub.math.univ-paris-diderot.fr (Postfix) with ESMTP id 5B3B570277 for ; Mon, 24 Feb 2014 14:48:34 +0100 (CET) X-Virus-Scanned: amavisd-new at math.univ-paris-diderot.fr Received: from mailhub.math.univ-paris-diderot.fr ([127.0.0.1]) by mailhub.math.univ-paris-diderot.fr (mailhub.math.univ-paris-diderot.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id JHvfEUDV1cTE for ; Mon, 24 Feb 2014 14:48:33 +0100 (CET) Received: from [10.11.111.192] (daimi-pat.daimi.au.dk [130.225.0.251]) (Authenticated sender: puech) by mailhub.math.univ-paris-diderot.fr (Postfix) with ESMTPSA id 088A47027A for ; Mon, 24 Feb 2014 14:48:32 +0100 (CET) Message-ID: <530B4DB0.4040203@pps.univ-paris-diderot.fr> Date: Mon, 24 Feb 2014 14:48:32 +0100 From: Matthias Puech User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131103 Icedove/17.0.10 MIME-Version: 1.0 To: caml-list@inria.fr References: <5309E82E.5060802@gmail.com> <530A590B.2040004@gmail.com> In-Reply-To: <530A590B.2040004@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.2.7 (korolev.univ-paris7.fr [IPv6:2001:660:3301:8000::1:2]); Mon, 24 Feb 2014 14:48:34 +0100 (CET) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.2.7 (potemkin.univ-paris7.fr [194.254.61.141]); Mon, 24 Feb 2014 14:48:34 +0100 (CET) X-Miltered: at korolev with ID 530B4DB2.002 by Joe's j-chkmail (http : // j-chkmail dot ensmp dot fr)! X-Miltered: at potemkin with ID 530B4DB2.001 by Joe's j-chkmail (http : // j-chkmail dot ensmp dot fr)! X-j-chkmail-Enveloppe: 530B4DB2.002 from potemkin.univ-paris7.fr/potemkin.univ-paris7.fr/null/potemkin.univ-paris7.fr/ X-j-chkmail-Enveloppe: 530B4DB2.001 from mailhub.math.univ-paris-diderot.fr/mailhub.math.univ-paris-diderot.fr/null/mailhub.math.univ-paris-diderot.fr/ X-j-chkmail-Score: MSGID : 530B4DB2.002 on korolev.univ-paris7.fr : j-chkmail score : . : R=. U=. O=. B=0.000 -> S=0.000 X-j-chkmail-Score: MSGID : 530B4DB2.001 on potemkin.univ-paris7.fr : j-chkmail score : . : R=. U=. O=. B=0.000 -> S=0.000 X-j-chkmail-Status: Ham X-j-chkmail-Status: Ham Subject: Re: [Caml-list] how to convert strings to Ocaml values at run-time? Hi, I am not sure if I understand your question correctly, but I guess you could: - lex/parse the string to an untyped type of AST [term] as usual, and then - have the type checking function take a [term] and produce an AST annotated with types ['a typed_term]. This type could be either: - a GADT, in which case you would need an evaluation function [eval : type a. a typed_term -> a], by recursion on the typed term - or, à la Finally Tagless [1], an abstract type declared in a module together with values implementing the various primitives. The thing to remember here I think is to "box" the type ['a] of the expression parsed into a type annotation, i.e., ['a typed_term]. However, I fear it is going to be difficult to extend this approach to polymorphism. Hope it helps, -m [1]: http://okmij.org/ftp/tagless-final/#tagless-final On 02/23/2014 09:24 PM, Matej Kosik wrote: > On 23/02/14 13:12, Tianyi Cui wrote: >> If you know the type of this string in advance, you can do so with ocaml_plugin: https://github.com/janestreet/ocaml_plugin > Hm, imagine that the expected type is: > > 'a * 'a -> bool > > Now, if user provides a string, say: > > "fun (a,b) -> a = b" > > how can I convert that string to Ocaml value of the above type (like how toplevel does it)? > > Is this something ocaml_plugin is able to do for me? I've failed to figure out the trick. >