yi lu | 1 Sep 08:02 2013
Picon

Can I use String without "" in ghci?

I want to know if it is possible that I use strings without "".

If I type
Prelude>foo bar
which actually I mean
Prelude>foo "bar"
However I don't want to type ""s.

I have noticed if bar 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 ping 127.0.0.1 where 127.0.0.1 is an argument.

If not, can foo be defined as a function so that it recognize arguments like bar as "bar"?


Thanks,
Yi Lu
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Mateusz Kowalczyk | 1 Sep 08:41 2013
Picon

Re: Can I use String without "" in ghci?

On 01/09/13 07:02, yi lu wrote:
> I want to know if it is possible that I use strings without "".
> 
> If I type
> *Prelude>foo bar*
> which actually I mean
> *Prelude>foo "bar"*
> However I don't want to type ""s.
> 
> I have noticed if *bar* 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
> *ping 127.0.0.1* where *127.0.0.1* is an argument.
> 
> If not, can *foo* be defined as a function so that it recognize arguments
> like *bar* as *"bar"*?
> 
> 
> Thanks,
> Yi Lu
> 
> 
You can't do this non-trivially. I think your only bet would be Template
Haskell using the second approach and even then, it's a huge, huge
stretch. I highly recommend against such ideas though. Do you really
want anything that's not bound to be treated as a String? (The answer is
‘no’). I suggest that you get used to ‘"’s.

If you have deep hatred for ‘"’, you could resort to spelling out the
strings like ['f', 'o', 'o'] or even 'f':'o':'o':[].

It's a bit like asking whether you can do addition everywhere by just
typing the numbers to each other (no cheating and defining number
literals as functions ;) ).

--

-- 
Mateusz K.
Albert Y. C. Lai | 1 Sep 18:21 2013
Picon

Re: Can I use String without "" in ghci?

On 13-09-01 02:41 AM, Mateusz Kowalczyk wrote:
> It's a bit like asking whether you can do addition everywhere by just
> typing the numbers to each other (no cheating and defining number
> literals as functions ;) ).

To your horror, common math language does some of that.

When 3 and ½ are typed next to each other, i.e.,

   3½

it is addition.

See also
page 8 in http://www.cs.utexas.edu/users/EWD/ewd13xx/EWD1300.PDF
or
look for "Invisible operators" in 
http://www.cs.utexas.edu/users/EWD/transcriptions/EWD13xx/EWD1300.html

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Michael Sloan | 1 Sep 18:29 2013
Picon

Re: Can I use String without "" in ghci?

Not that I really want to encourage such a "stringly typed" practice, but it wouldn't really be that much of a stretch.

* Use haskell-src-exts[0] and haskell-src-meta[1] to make a quasiquoter that can parse Haskell syntax
* Use syb[2] or some other generics to find VarE and ConE expressions.  In order to use SYB with TH, you'll want th-orphans[3]
* Use 'reify'[4] on the name of the variable or constructor, to see if it exists.  If it doesn't[5], replace it with (LitE (StringL (nameBase name)))

Shouldn't really be much code at all! :D

-Michael

[0] http://hackage.haskell.org/package/haskell-src-exts
[1] http://hackage.haskell.org/package/haskell-src-meta
[2] http://hackage.haskell.org/package/syb
[3] http://hackage.haskell.org/package/th-orphans
[4] http://hackage.haskell.org/packages/archive/template-haskell/latest/doc/html/Language-Haskell-TH.html#v:reify
[5] http://byorgey.wordpress.com/2011/08/16/idempotent-template-haskell/


On Sat, Aug 31, 2013 at 11:41 PM, Mateusz Kowalczyk <fuuzetsu <at> fuuzetsu.co.uk> wrote:
On 01/09/13 07:02, yi lu wrote:
> I want to know if it is possible that I use strings without "".
>
> If I type
> *Prelude>foo bar*
> which actually I mean
> *Prelude>foo "bar"*
> However I don't want to type ""s.
>
> I have noticed if *bar* 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
> *ping 127.0.0.1* where *127.0.0.1* is an argument.
>
> If not, can *foo* be defined as a function so that it recognize arguments
> like *bar* as *"bar"*?
>
>
> Thanks,
> Yi Lu
>
>
You can't do this non-trivially. I think your only bet would be Template
Haskell using the second approach and even then, it's a huge, huge
stretch. I highly recommend against such ideas though. Do you really
want anything that's not bound to be treated as a String? (The answer is
‘no’). I suggest that you get used to ‘"’s.

If you have deep hatred for ‘"’, you could resort to spelling out the
strings like ['f', 'o', 'o'] or even 'f':'o':'o':[].

It's a bit like asking whether you can do addition everywhere by just
typing the numbers to each other (no cheating and defining number
literals as functions ;) ).

--
Mateusz K.

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Albert Y. C. Lai | 1 Sep 18:11 2013
Picon

Re: Can I use String without "" in ghci?

On 13-09-01 02:02 AM, yi lu wrote:
> I have noticed if *bar* 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 *ping 127.0.0.1* where *127.0.0.1* is an argument.

Does Bash have a rich type system, like Haskell?

Does Haskell use "$joy" to refer to a variable, and "joy" to not refer 
to a variable, like Bash?
Richard A. O'Keefe | 2 Sep 02:13 2013
Picon

Re: Can I use String without "" in ghci?


On 1/09/2013, at 6:02 PM, yi lu wrote:

> I want to know if it is possible that I use strings without "".
> 
> If I type
> Prelude>foo bar
> which actually I mean
> Prelude>foo "bar"
> However I don't want to type ""s.
> 
> I have noticed if bar is predefined or it is a number, it can be used as arguments. But can other strings be
used this way?

If bar is predefined, it *isn't* the string 'b':'a':'r':[].
If bar is a number, it *isn't* a string.
So "other strings" is quite misleading.

In Haskell, if you use strings a lot, you are probably doing
something wrong.  For things that are not text manipulation
tasks, there is practically always a better type, and these
days, for things that _are_ text manipulation, there is
practically always a better type.

A slogan I have programmed by since I first met C and recognised
how vastly superior to PL/I it was for text manipulation _because_
it didn't have a proper string type is "Strings are Wrong!".
Rustom Mody | 2 Sep 05:55 2013
Picon

Re: Can I use String without "" in ghci?

On Mon, Sep 2, 2013 at 5:43 AM, Richard A. O'Keefe  wrote:

A slogan I have programmed by since I first met C and recognised
how vastly superior to PL/I it was for text manipulation _because_
it didn't have a proper string type is "Strings are Wrong!".

I wonder if you notice the irony in your use of 'C' as exemplar in this context?

C rode to fame on the back of Unix. And Unix'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.

Of course when instructing a beginning programmer your basic premise 'Strings are Wrong!' is most likely right.  However if programs are seen as entities interacting with an 'external' world, the currency at the portals is invariably string.  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. So while this is true:

If bar is predefined, it *isn't* the string 'b':'a':'r':[].
If bar is a number, it *isn't* a string.
So "other strings" is quite misleading.

 in the innards of haskell, bar is a string


On Sun, Sep 1, 2013 at 9:51 PM, Albert Y. C. Lai wrote:
When 3 and ½ are typed next to each other, i.e.,

  3½

it is addition.


Well mathematicians are always eliding!

In 3½ the elision amounts to +
In xy it amounts to *
And within 23 ie between the 2 and the 3, it amounts to λ x y -> 10*x + y

And Haskell elides function application

When teaching gofer (in the early 90s) I found that undoing the elision of function application and making it explicit, made FP more withing reach of the kids.


Rusi
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Richard A. O'Keefe | 2 Sep 07:13 2013
Picon

Re: Can I use String without "" in ghci?


On 2/09/2013, at 3:55 PM, Rustom Mody wrote:

> On Mon, Sep 2, 2013 at 5:43 AM, Richard A. O'Keefe  wrote:
> 

> A slogan I have programmed by since I first met C and recognised
> how vastly superior to PL/I it was for text manipulation _because_
> it didn't have a proper string type is "Strings are Wrong!".
> 
> I wonder if you notice the irony in your use of 'C' as exemplar in this context?

In all seriousness, a text editor application written in C was
*an order of magnitude* smaller in C than in PL/I *because* of
the lack of a string data type.

> C rode to fame on the back of Unix. And Unix'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.

The idea of file names being strings was no innovation.
Yes, in crippled monstrosities like TOPS-10 file names were
weird records -- I can still remember too much of the details --
and every ruddy TOPS-10 program had to do its own file name
parsing and it seemed as if they all did it differently.  But
the B6700 MCP interfaces treated file names as strings before
UNIX was dreamed of.

File contents in UNIX are *not* strings and never have been --
NUL termination is no part of files and binary files have been
commonplace since the beginning (an a.out file is not a string!).
They are *byte arrays*.

As for IPC, since when have System V shared memory, semaphores,
or message queues had anything to do with strings?
(Hint: the 'name' of a System V shared memory segment is a
 key_t, and that's an integral type, not a string.
 Hint: the 'name' of a System V semaphore is also a key_t
 integer, not a string.
 Hint: the 'name' of a System V message queue is also a key_t
 integer, not a string.
 Hint: messages sent using msgsnd are not strings, they are
 byte arrays with a separate count parameter.
)

Classic UNIX uses strings for file names, and really, that's it.
(The command line argv[] is not really an exception, because it
was used for file names as well as options, and in fact mixing
the two up caused endless problems.)
Everything else in V7, S3, or SysV was identified by a *number*.
Plan 9 has exit(string) but Unix has exit(byte).

From the perspective of someone who used UNIX v6 in 1979,
*POSIX* IPC -- with its IPC objects *might* be in the file
system but then again might *not* be so their names are
sorta-kinda-like file names but not really) -- and /proc are
recent innovations.

The idea that 'string' was even remotely like a "universal type"
in UNIX is bizarre.

Heck, UNIX never even used 'string' for *lines* in text files!

> Of course when instructing a beginning programmer your basic premise 'Strings are Wrong!' is most likely right.

No, I'm talking about experienced programmers writing high performance
programs.

>  However if programs are seen as entities interacting with an 'external' world, the currency at the
portals is invariably string.

- The currency at the portals is *not* invariably string.
  Learn PowerShell.
- "Text" is one thing and "string" is another.  This was the
  B6700 lesson (well, really the B5500 lesson): for many purposes
  you want a text *stream* not a text *string* at the interface.
  It's also the what-Smalltalk-got-right-and-Java-got-wrong
  lesson: the right way to convert objects to text is via a
  *stream* interface, not a *string* interface.

>  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.

Hang on, they are there in order to *support* the "numbers are text" model.
You can't have it both ways.

> So while this is true:
> 
> If bar is predefined, it *isn't* the string 'b':'a':'r':[].
> If bar is a number, it *isn't* a string.
> So "other strings" is quite misleading.
> 
>  in the innards of haskell, bar is a string

No, in the innards of Haskell, bar is possibly a number,
possibly a pointer to some sort of record, possibly some
other data structure, but almost certainly *not* a string.

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Gmane