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

Michael Sloan mgsloan at gmail.com
Sun Sep 1 18:29:44 CEST 2013


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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130901/84efb23c/attachment.htm>


More information about the Haskell-Cafe mailing list