[Haskell-cafe] Can I use String without "" in ghci?

Mateusz Kowalczyk fuuzetsu at fuuzetsu.co.uk
Sun Sep 1 08:41:59 CEST 2013


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.




More information about the Haskell-Cafe mailing list