* Re: [Caml-list] type-safe printf
2016-09-13 15:12 [Caml-list] type-safe printf Андрей Бергман
@ 2016-09-13 15:25 ` Mario Pereira
2016-09-13 15:36 ` Maxime Dénès
2016-09-13 15:31 ` Kakadu
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Mario Pereira @ 2016-09-13 15:25 UTC (permalink / raw)
To: caml-list
Hi,
You can do it using GADTs. However, I am not sure if this is explained
somewhere.
Le 13/09/2016 à 17:12, Андрей Бергман a écrit :
> Hello,
>
> is there a good article or just short explanation how compile-type checking of Printf arguments works?
>
> Does it require special compiler support like in C++ compilers/analyzers, or one can somehow do the trick of parsing string literal using Ocaml language itself? (actually latter does not look possible to me)
>
> Thanks,
> Andrey.
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] type-safe printf
2016-09-13 15:25 ` Mario Pereira
@ 2016-09-13 15:36 ` Maxime Dénès
0 siblings, 0 replies; 8+ messages in thread
From: Maxime Dénès @ 2016-09-13 15:36 UTC (permalink / raw)
To: caml-list
Hello,
Some ideas are described here:
https://ocaml.org/meetings/ocaml/2013/proposals/formats-as-gadts.pdf
Maxime.
On 09/13/16 17:25, Mario Pereira wrote:
> Hi,
>
> You can do it using GADTs. However, I am not sure if this is explained
> somewhere.
>
> Le 13/09/2016 à 17:12, Андрей Бергман a écrit :
>> Hello,
>>
>> is there a good article or just short explanation how compile-type
>> checking of Printf arguments works?
>>
>> Does it require special compiler support like in C++
>> compilers/analyzers, or one can somehow do the trick of parsing string
>> literal using Ocaml language itself? (actually latter does not look
>> possible to me)
>>
>> Thanks,
>> Andrey.
>>
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] type-safe printf
2016-09-13 15:12 [Caml-list] type-safe printf Андрей Бергман
2016-09-13 15:25 ` Mario Pereira
@ 2016-09-13 15:31 ` Kakadu
2016-09-13 15:40 ` Daniel Bünzli
2016-09-14 11:19 ` Oleg
2016-09-13 15:38 ` David Allsopp
2016-09-13 17:54 ` Андрей Бергман
3 siblings, 2 replies; 8+ messages in thread
From: Kakadu @ 2016-09-13 15:31 UTC (permalink / raw)
To: Андрей
Бергман
Cc: Caml List
Functional unparsing by Olivier Danvy can be related article.
http://www.brics.dk/RS/98/12/BRICS-RS-98-12.pdf
Happy hacking,
Kakadu
On Tue, Sep 13, 2016 at 6:12 PM, Андрей Бергман <vkni@yandex.ru> wrote:
> Hello,
>
> is there a good article or just short explanation how compile-type checking of Printf arguments works?
>
> Does it require special compiler support like in C++ compilers/analyzers, or one can somehow do the trick of parsing string literal using Ocaml language itself? (actually latter does not look possible to me)
>
> Thanks,
> Andrey.
>
> --
> Caml-list mailing list. Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [Caml-list] type-safe printf
2016-09-13 15:12 [Caml-list] type-safe printf Андрей Бергман
2016-09-13 15:25 ` Mario Pereira
2016-09-13 15:31 ` Kakadu
@ 2016-09-13 15:38 ` David Allsopp
2016-09-13 17:54 ` Андрей Бергман
3 siblings, 0 replies; 8+ messages in thread
From: David Allsopp @ 2016-09-13 15:38 UTC (permalink / raw)
To: Андрей
Бергман,
caml-list
Андрей Бергман wrote:
> is there a good article or just short explanation how compile-type
> checking of Printf arguments works?
>
>
> Does it require special compiler support like in C++ compilers/analyzers,
> or one can somehow do the trick of parsing string literal using Ocaml
> language itself? (actually latter does not look possible to me)
It does require a certain amount of special support, yes - see the Pexp_constant(Pconst_string _) case in typing/typecore.ml, in particular the comment "Terrible hack for format strings"! In essence, a string is "magically" interpreted as a format string if it is used in a context where one would be expected (e.g. the usual Printf.printf). It's one of the reasons Pervasives.format_of_string exists (because they're type- rather than syntax-driven).
From that point onwards, it's a lot of GADTs, but doesn't require any special language support!
If you were adding Printf to OCaml for the first time now, you'd probably use quoted string literals instead (see http://caml.inria.fr/pub/docs/manual-ocaml/extn.html#sec249) - and the entire thing would then be in OCaml with no special case hacks.
David
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] type-safe printf
2016-09-13 15:12 [Caml-list] type-safe printf Андрей Бергман
` (2 preceding siblings ...)
2016-09-13 15:38 ` David Allsopp
@ 2016-09-13 17:54 ` Андрей Бергман
3 siblings, 0 replies; 8+ messages in thread
From: Андрей Бергман @ 2016-09-13 17:54 UTC (permalink / raw)
To: caml-list
Thank you all very much! Your references and explanations made it clear to me.
13.09.2016, 18:19, "Андрей Бергман" <vkni@yandex.ru>:
> Hello,
>
> is there a good article or just short explanation how compile-type checking of Printf arguments works?
>
> Does it require special compiler support like in C++ compilers/analyzers, or one can somehow do the trick of parsing string literal using Ocaml language itself? (actually latter does not look possible to me)
>
> Thanks,
> Andrey.
>
> --
> Caml-list mailing list. Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
^ permalink raw reply [flat|nested] 8+ messages in thread