<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2002/07/55221a6e50e64420b97504ccc84af871"
  from="Alessandro Baretta &lt;alex@b...&gt;"
  author="Alessandro Baretta"
  date="2002-07-12T13:25:23"
  subject="Re: [Caml-list] Scanf [was: Productivity improvement]"
  prev="2002/07/7855b27bc335084ddfab207def619738"
  next="2002/07/c8beb5cb79a1699cf82fbd47088bda43"
  next-in-thread="2002/07/2451d08e6dbf20fc50c7b355b483fac1"
  prev-thread="2002/07/b0c7298c9c0bead77bcf8ed319d71bf4"
  next-thread="2002/07/e2f2b258abd0d3497431776b34442703"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="Re: [Caml-list] Scanf [was: Productivity improvement]">
<msg 
  url="2002/07/55221a6e50e64420b97504ccc84af871"
  from="Alessandro Baretta &lt;alex@b...&gt;"
  author="Alessandro Baretta"
  date="2002-07-12T13:25:23"
  subject="Re: [Caml-list] Scanf [was: Productivity improvement]">
<msg 
  url="2002/07/2451d08e6dbf20fc50c7b355b483fac1"
  from="Pierre Weis &lt;pierre.weis@i...&gt;"
  author="Pierre Weis"
  date="2002-07-12T17:43:15"
  subject="Re: [Caml-list] Scanf [was: Productivity improvement]">
</msg>
</msg>
</thread>

<contents>
Pierre Weis wrote:
&gt;&gt;
&gt;&gt;The fact is, I don't like the look and feel of Unix scanf 
&gt;&gt;and printf.
&gt; 
&gt; 
&gt; However, if what you dislike about those functions is the conciseness
&gt; of the format strings, there is not much to say ...
&gt; 

Not the conciseness, of course. I dislike the lack of 
readability of format strings. I'd like to write:
let format = int + float + float + string + int
and, voilą mon format! Then there would have to be some 
additional details such as having a scanf function taking an 
in_channel, a format such as the above, and


&gt;&gt;I'd rather something simpler, that does not 
&gt;&gt;require compiler magic. Scanf and printf require compiler 
&gt;&gt;magic even the the almost typeless C language. Is it not 
&gt;&gt;incoherent to maintain virtually untypeable constructs in a 
&gt;&gt;language that claims to have a bullet-proof type system? 
&gt;&gt;(With the sole exception of Obj.magic)
&gt; 
&gt; 
&gt; I claim that scanf and printf are statically type checked in Caml, and
&gt; require no magic from the user nor from the compiler (except evidently
&gt; the addition of an extra typing rule for the proper typechecking of
&gt; those format string constants, exactly as we have typechecking rules
&gt; for other complex structured constants such as lists or vectors or
&gt; strings). I think the Caml implementation is clean, except for the
&gt; fact that string format constants cannot be lexically distinguished
&gt; from ordinary string constants. However, this little glitch has never
&gt; been reported by any of our users who seem to be happy with this
&gt; little flavor of overloading in the language.

Ah, so this is how the "magic" from the compiler works. 
Formats are string literals only in the concrete syntax of 
the language; whereas, in the abstract syntax, formats are a 
different type. The typing machinery behind looks more 
complicated than I dare delve into for now

&gt; Look at the transposition of your code in Caml: our scanf and printf
&gt; functions are not mere transpositions of the equivalent C
&gt; functions. They are more functional in spirit and much less error
&gt; prone than their C equivalent, since they are fully typechecked (and
&gt; there are no 0 valued argument provided by default, nor multiple usage
&gt; of the same format to parse extra arguments, nor any of such error
&gt; prone unique (mis-)features).

Alright. They probably resemble their C counterparts so much 
that I have overlooked the differences.

&gt; In effect, given that the typing rule is based on the ('a, 'b, 'c)
&gt; format type constructor, so higly polymorphic that many people do not
&gt; understand it at all (let alone its unification and interaction with
&gt; the definition types of printf and scanf-like functions); given that
&gt; the Caml code for those primitives is entirely based on continuations
&gt; (that many people found difficult to use and masterize); we can state
&gt; that the scanf and printf features are based on polymorphism and
&gt; continuations. Polymorphism and continuations are often considered as
&gt; the distinguished features of ML-like languages, precisely in the
&gt; "duro e puro" kernel of functional languages :)

IOW, you are telling me I should study the details of the 
machinery behind scanf and printf. I will. But I still 
wonder if I can cook up a working, toy example, of the 
scanf-I've-always-dreamt-of-but-never-dared-to-code.

Alex

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners

</contents>

</message>

