<div dir="ltr"><div>On Mon, Sep 2, 2013 at 10:43 AM, Richard A. O&#39;Keefe <span dir="ltr">&lt;<a href="mailto:ok@cs.otago.ac.nz" target="_blank">ok@cs.otago.ac.nz</a>&gt;</span> wrote:<br>










<div class="gmail_quote"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div class="im"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

<div><br>
On 2/09/2013, at 3:55 PM, Rustom Mody wrote:<br>
<br>
&gt; On Mon, Sep 2, 2013 at 5:43 AM, Richard A. O&#39;Keefe  wrote:<br>
&gt;<br>
<br>
&gt; A slogan I have programmed by since I first met C and recognised<br>
&gt; how vastly superior to PL/I it was for text manipulation _because_<br>
&gt; it didn&#39;t have a proper string type is &quot;Strings are Wrong!&quot;.<br>
&gt;</div></blockquote></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>
&gt; C rode to fame on the back of Unix. And Unix&#39;s innovation – one of many – is that at the OS level the string type was made common fare – a universal type.  So everything from file names to file contents to IPC is a string.<br>













<br>
</div><div class="im">The idea of file names being strings was no innovation.<br>
Yes, in crippled monstrosities like TOPS-10 file names were<br>
weird records -- I can still remember too much of the details --<br>
and every ruddy TOPS-10 program had to do its own file name<br>
parsing and it seemed as if they all did it differently.  But<br>
the B6700 MCP interfaces treated file names as strings before<br>
UNIX was dreamed of.<br>
<br>
File contents in UNIX are *not* strings and never have been --<br>
NUL termination is no part of files and binary files have been<br>
commonplace since the beginning (an a.out file is not a string!).<br>
They are *byte arrays*.<br>
<br>
As for IPC, since when have System V shared memory, semaphores,<br>
or message queues had anything to do with strings?<br>
(Hint: the &#39;name&#39; of a System V shared memory segment is a<br>
 key_t, and that&#39;s an integral type, not a string.<br>
 Hint: the &#39;name&#39; of a System V semaphore is also a key_t<br>
 integer, not a string.<br>
 Hint: the &#39;name&#39; of a System V message queue is also a key_t<br>
 integer, not a string.<br>
 Hint: messages sent using msgsnd are not strings, they are<br>
 byte arrays with a separate count parameter.<br>
)<br>
<br></div></blockquote><div><br></div><div>Whoops!  my bad -- I was *thinking* &#39;pipes&#39; but ended up *writing* &#39;IPC&#39;   :-)<br><br></div><div>So let me restate more explicitly what I intended -- pipes, FIFOs, sockets, etc.<br>












</div><div>IOW read/write/send/recv calls and the mathematical model represented by the (non-firstclass) pair of C data structures in those functions: &lt;buf, len&gt; (or count).<br></div><div><br>As an aside: modern usage types the buf as void * .  The version 7 unix manuals on which I grew up (and first edition of K&amp;R), there was no void; buf would be just &#39;char *buf; &#39;<br>










</div><div><div class="h5"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Classic UNIX uses strings for file names, and really, that&#39;s it.<br>
(The command line argv[] is not really an exception, because it<br>
was used for file names as well as options, and in fact mixing<br>
the two up caused endless problems.)<br>
Everything else in V7, S3, or SysV was identified by a *number*.<br>
Plan 9 has exit(string) but Unix has exit(byte).<br>
<br>
>From the perspective of someone who used UNIX v6 in 1979,<br>
*POSIX* IPC -- with its IPC objects *might* be in the file<br>
system but then again might *not* be so their names are<br>
sorta-kinda-like file names but not really) -- and /proc are<br>
recent innovations.<br>
<br>
The idea that &#39;string&#39; was even remotely like a &quot;universal type&quot;<br>
in UNIX is bizarre.<br>
<br>
Heck, UNIX never even used &#39;string&#39; for *lines* in text files!<br>
<div><br>
&gt; Of course when instructing a beginning programmer your basic premise &#39;Strings are Wrong!&#39; is most likely right.<br>
<br>
</div>No, I&#39;m talking about experienced programmers writing high performance<br>
programs.<br>
<div><br>
&gt;  However if programs are seen as entities interacting with an &#39;external&#39; world, the currency at the portals is invariably string.<br>
<br>
</div>- The currency at the portals is *not* invariably string.<br>
  Learn PowerShell.<br>
- &quot;Text&quot; is one thing and &quot;string&quot; is another.  This was the<br>
  B6700 lesson (well, really the B5500 lesson): for many purposes<br>
  you want a text *stream* not a text *string* at the interface.<br>
  It&#39;s also the what-Smalltalk-got-right-and-Java-got-wrong<br>
  lesson: the right way to convert objects to text is via a<br>
  *stream* interface, not a *string* interface.<br>
</blockquote><div><br></div></div></div><div>I realize this is a terminology issue:<br><br>My usage of terminology like string/file are evidently more aligned to<br><a href="http://en.wikipedia.org/wiki/Vienna_Development_Method#Collections:_Sets.2C_Mappings_and_Sequences" target="_blank">http://en.wikipedia.org/wiki/Vienna_Development_Method#Collections:_Sets.2C_Mappings_and_Sequences</a><br>


</div><div>file(chap 4): <a href="http://red.cs.nott.ac.uk/~rxq/files/SpecificationCaseStudies.pdf" target="_blank">http://red.cs.nott.ac.uk/~rxq/files/SpecificationCaseStudies.pdf</a><br><br></div><div>Contrariwise &#39;file&#39; can mean <a href="http://en.wikipedia.org/wiki/Data_set_%28IBM_mainframe%29" target="_blank">http://en.wikipedia.org/wiki/Data_set_%28IBM_mainframe%29</a><br>


</div><div><br></div>So coming back from terminology to principles...<br></div><div class="im"><div class="gmail_quote"><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">










<div>
&gt;  And more than just noob programmers have got this wrong – think of the precious one-byte opcodes that Intel wastes on ascii and decimal arithmetic.<br>
<br>
</div>Hang on, they are there in order to *support* the &quot;numbers are text&quot; model.<br>
You can&#39;t have it both ways.<br>
</blockquote><div><br clear="all"></div></div></div>So let me restate (actually I didn&#39;t state it earlier!) my point in this example:<br><br></div><div class="gmail_extra">When Intel introduced these instructions in 8008 (or whatever) decades ago, it seemed like a good idea to help programmers and reduce their burden by allowing them to do some minimal arithmetic on data without burdensome conversion-to-binary functions.<br>










<br></div><div class="gmail_extra">4 decades on and (Intel&#39;s very own Gordon) Moore&#39;s law ensuring our machines and networks some 7 orders of magnitude larger, the cost-equations look different.  printf and scanf are a basic given in any C library so optimizing them out does not optimize anything.<br>










<br></div><div class="gmail_extra">On the other hand having instructions --that too 1-byte instructions -- that are almost never used is terribly inefficient:<br></div><div class="gmail_extra">- the extra transistors in the millions of CPUs that are never used<br>










</div><div class="gmail_extra">- the instructions that are used become fatter.  Multiply by the GBs per installation multipled by millions of installations.<br><br></div><div class="gmail_extra">And so Intel made (makes) the same mistake that the typical programmer-noob makes, which you capture pithily in your &#39;Strings are wrong!&#39; Put slightly more verbosely:<br>



<br>






</div><div class="gmail_extra">Strings (or byte-arrays if you prefer) are invariably what come into and go out of your program.<br></div><div class="gmail_extra">Keep them that way and you reduce your work in the immediate term but increase it in the long term since it is almost always a bad fit for both problem-domain and machine-model. Building appropriate models is the central business of programmers<br>









<br></div><div class="gmail_extra">Brings me to the OPs question:<br><br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><div class="im"> I want to know if it is possible that I use strings without &quot;&quot;.<br>









<br><div>If I type<br></div><b>Prelude&gt;foo bar</b><br>which actually I mean<br>
<b>Prelude&gt;foo &quot;bar&quot;</b><br>However I don&#39;t want to type &quot;&quot;s.<br><br></div><div class="im">I have noticed if <b>bar</b> is predefined or it is a number, it can be used as arguments. But can other strings be used this way? Like in bash, we can use <b>ping 127.0.0.1</b> where <b>127.0.0.1</b> is an argument.<br>










<br>If not, can <b>foo</b> be defined as a function so that it recognize arguments like <b>bar</b> as <b>&quot;bar&quot;</b>?<br></div></blockquote><br></div><div class="gmail_extra">Its not clear what your use-case is.<br>

<br>







</div><div class="gmail_extra">1. In the simplest and most common case, a few data declarations will give you what you want.  eg if in place of bar you have (a few) colors like red, green etc you can do<br></div><div class="gmail_extra">









data Color = Red | Green...<br>
</div><div class="gmail_extra">and your strings like &quot;red&quot; &quot;green&quot; will disappear and become Red Green etc<br></div><div class="gmail_extra">IOW if your &quot;bar&quot; and like strings is a small enumerate-able set then make a corresponding enumerated type. Thereafter haskell will do the quoting for you.<br>



</div><div class="gmail_extra"><br></div><div class="gmail_extra">For the IP example you dont even need a data; just type<br>





</div><div class="gmail_extra">type IP = (Int,Int,Int,Int)<br></div><div class="gmail_extra">or if you prefer<br></div><div class="gmail_extra">type IP = (Word8,Word8,Word8,Word8)<br></div><div class="gmail_extra">and then the shell 127.0.0.1 would be the haskell (127,0,0,1)<br>









<br><div class="gmail_extra">Sometimes though one may prefer to be a little pedantic and write<br></div><div class="gmail_extra">newtype IP = IP  (Word8,Word8,Word8,Word8)<br>

</div><div class="gmail_extra"><br></div></div><div class="gmail_extra">Note the exact fit of the Word8 to the IP spec.<br></div><div class="gmail_extra">And the corresponding non-exact fit with the string form: What happens when you<br>







</div><div class="gmail_extra">see the string, &quot;500.1000.1.2&quot; ? You need to decide...<br><br></div><div class="gmail_extra">Beyond that, as others have shown you may want to consider building your own DSL perhaps using template haskell<br>


 


<br>Beyond that... are you sure shell is not what you want?<br><br></div><div class="gmail_extra">ie if you need full haskell power, and typical shell quoting behavior and you have thought through a design that is sound and consistent (note Albert&#39;s refs above to $ usage in shell) then I (and I guess many others here) will want to hear of it!!<br>









<br></div><div class="gmail_extra">However for starters you probably dont want to go beyond just defining well-fitting datas and types and many of the &quot;..&quot; will vanish from your code<br></div><div class="gmail_extra">







<br>


</div></div>
</div><br><br clear="all"></div>Rusi<br><div><br>-- <br><a href="http://www.the-magus.in" target="_blank">http://www.the-magus.in</a><br><a href="http://blog.languager.org" target="_blank">http://blog.languager.org</a><br>

<br>
</div></div>