
Hey all - I've been trying to write an IRC bot following the guide on the wiki, and we (those of us on the channel) were trying to get it to evaluate commands. So far, we have this for "eval" stuff, but is there anyway to specify a "parse in haskell" sort of thing? [code] -- Dispatch a command eval :: String -> Net () eval "!endbot" = write "QUIT" ":Exiting" >> io (exitWith ExitSuccess) eval x | "!haskbot " `isPrefixOf` x = privmsg (drop 9 x) eval _ = return () -- ignore everything else [/code] is there anyway to do something like: eval "!eval" `isPrefixOf` x = eval blah ? if this isn't beginners' stuff, let me know, i'll repost to the main mailing list. Many thanks, Alex Shearn -- The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336.

On 2008 Oct 27, at 17:33, Alex Shearn wrote:
Hey all - I've been trying to write an IRC bot following the guide on the wiki, and we (those of us on the channel) were trying to get it to evaluate commands. So far, we have this for "eval" stuff, but is there anyway to specify a "parse in haskell" sort of thing?
No, although you could fake it with the GHC-API (which basically means your bot has all of GHC built into it). In any case, that's not really a good idea; consider what damage could be done by arbitrary code. A better idea is to link the code into a small program with a very restricted environment and run that with a timeout. See http://code.haskell.org/lambdabot/Plugin/Eval.hs. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

On Mon, Oct 27, 2008 at 07:00:00PM -0400, Brandon S. Allbery KF8NH wrote:
On 2008 Oct 27, at 17:33, Alex Shearn wrote:
Hey all - I've been trying to write an IRC bot following the guide on the wiki, and we (those of us on the channel) were trying to get it to evaluate commands. So far, we have this for "eval" stuff, but is there anyway to specify a "parse in haskell" sort of thing?
No, although you could fake it with the GHC-API (which basically means your bot has all of GHC built into it).
In any case, that's not really a good idea; consider what damage could be done by arbitrary code. A better idea is to link the code into a small program with a very restricted environment and run that with a timeout. See http://code.haskell.org/lambdabot/Plugin/Eval.hs.
Brandon is right that this is difficult and tricky -- but fortunately, someone else has already done the hard work for you! Take a look at the mueval package [1], which should allow you to do what you want. -Brent [1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/mueval

On Mon, Oct 27, 2008 at 07:45:26PM -0400, Brent Yorgey wrote:
On Mon, Oct 27, 2008 at 07:00:00PM -0400, Brandon S. Allbery KF8NH wrote:
On 2008 Oct 27, at 17:33, Alex Shearn wrote:
Hey all - I've been trying to write an IRC bot following the guide on the wiki, and we (those of us on the channel) were trying to get it to evaluate commands. So far, we have this for "eval" stuff, but is there anyway to specify a "parse in haskell" sort of thing?
No, although you could fake it with the GHC-API (which basically means your bot has all of GHC built into it).
In any case, that's not really a good idea; consider what damage could be done by arbitrary code. A better idea is to link the code into a small program with a very restricted environment and run that with a timeout. See http://code.haskell.org/lambdabot/Plugin/Eval.hs.
Brandon is right that this is difficult and tricky -- but fortunately, someone else has already done the hard work for you! Take a look at the mueval package [1], which should allow you to do what you want.
this raises a question for me, being a bit of a schemer. Is there any parallel in haskell to the data is code model of the lisp family? For example, playing around in scheme with a symbolic differentiator, it is trivial to then evaluate the differentiated s-expression at arbitrary value by representing the expression, and it's derivative as a regular scheme expression. Is this something that can be done in haskell? My initial impression is no, that you'd have to parse it as an expression and evaluate it as you would in regular imperative languages. I'd love to hear otherwise. A

On 2008 Oct 27, at 23:25, Andrew Sackville-West wrote:
this raises a question for me, being a bit of a schemer. Is there any parallel in haskell to the data is code model of the lisp family? For example, playing around in scheme with a symbolic differentiator, it is trivial to then evaluate the differentiated s-expression at arbitrary value by representing the expression, and it's derivative as a regular scheme expression.
Is this something that can be done in haskell? My initial impression is no, that you'd have to parse it as an expression and evaluate it as you would in regular imperative languages. I'd love to hear otherwise.
You get this in a type-safe form with Template Haskell; you can operate on expressions at the AST level. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

On Mon, Oct 27, 2008 at 11:26 PM, Brandon S. Allbery KF8NH < allbery@ece.cmu.edu> wrote:
On 2008 Oct 27, at 23:25, Andrew Sackville-West wrote:
this raises a question for me, being a bit of a schemer. Is there any parallel in haskell to the data is code model of the lisp family? For example, playing around in scheme with a symbolic differentiator, it is trivial to then evaluate the differentiated s-expression at arbitrary value by representing the expression, and it's derivative as a regular scheme expression.
Is this something that can be done in haskell? My initial impression is no, that you'd have to parse it as an expression and evaluate it as you would in regular imperative languages. I'd love to hear otherwise.
You get this in a type-safe form with Template Haskell; you can operate on expressions at the AST level.
Yeah, but can you do this at run time? I though Template Haskell can only be used at compile time.

On Tue, Oct 28, 2008 at 07:00:00PM -0400, Tony Hannan wrote:
On Mon, Oct 27, 2008 at 11:26 PM, Brandon S. Allbery KF8NH < allbery@ece.cmu.edu> wrote:
On 2008 Oct 27, at 23:25, Andrew Sackville-West wrote:
this raises a question for me, being a bit of a schemer. Is there any parallel in haskell to the data is code model of the lisp family? For example, playing around in scheme with a symbolic differentiator, it is trivial to then evaluate the differentiated s-expression at arbitrary value by representing the expression, and it's derivative as a regular scheme expression.
Is this something that can be done in haskell? My initial impression is no, that you'd have to parse it as an expression and evaluate it as you would in regular imperative languages. I'd love to hear otherwise.
You get this in a type-safe form with Template Haskell; you can operate on expressions at the AST level.
Yeah, but can you do this at run time? I though Template Haskell can only be used at compile time.
That's what I'm talking about, run time evaluation of code/data. In scheme, I can take as input (+ (exp x 2) (* 2 x)) a representation of x^2 + 2x I can feed that "data" into a function (derive input) and get back (+ (* 2 x) 2) a representation of 2x +2, the derivative of the above. The function derive can manipulate that "Data" which is just a list, or s-expression like any other data (for example accessing the first element in the list, determining that it's a '+' and so calling derive recursively on the two following elements). then I can feed that result into (eval) with some information about what the value of x is and it will be evaluated just like a regular scheme expression. something like (it's been a while): (let ((x 2)) (eval default-environment (derive (input)))) where default-environment lets you get the information about the current environment into the eval environment so that x has a value. So now, what was "Data" a moment ago is treated as executable within the eval. The above (let) would spit out(in this case) a value of 6. Is such a thing possible in haskell? (I'm really just curious, I have no need of this functionality at this point). Oh, and I apologise for the fingernail clippings... A --

Andrew Sackville-West schrieb:
this raises a question for me, being a bit of a schemer. Is there any parallel in haskell to the data is code model of the lisp family?
No.
My initial impression is no, that you'd have to parse it as an expression and evaluate it as you would in regular imperative languages. I'd love to hear otherwise.
I don't see how "code is data" is connected to imperative vs. purely functional. After all, lisp & co. are not purely functional, but feature "code is data". Another well-known symbolic language, which allows to treat code as data and vice versa, is prolog. Since Haskell features algebraic data types, and a reasonable flexible syntax, you do not need to do any parsing. Instead, you can write down the AST of the embedded language directly as part of your Haskell program. But you have to write an evaluator. With pattern matching, that is often very easy, though. Tillmann

On Wed, Oct 29, 2008 at 09:27:32AM +0100, Tillmann Rendel wrote:
Andrew Sackville-West schrieb:
this raises a question for me, being a bit of a schemer. Is there any parallel in haskell to the data is code model of the lisp family?
No.
My initial impression is no, that you'd have to parse it as an expression and evaluate it as you would in regular imperative languages. I'd love to hear otherwise.
I don't see how "code is data" is connected to imperative vs. purely functional. After all, lisp & co. are not purely functional, but feature "code is data". Another well-known symbolic language, which allows to treat code as data and vice versa, is prolog.
I didn't mean to connect the concept to imperative vs. functional.
Since Haskell features algebraic data types, and a reasonable flexible syntax, you do not need to do any parsing. Instead, you can write down the AST of the embedded language directly as part of your Haskell program. But you have to write an evaluator. With pattern matching, that is often very easy, though.
looks like I'm off to read about Template Haskell. thanks to all. A

On Wed, Oct 29, 2008 at 07:02:46AM -0700, Andrew Sackville-West wrote:
On Wed, Oct 29, 2008 at 09:27:32AM +0100, Tillmann Rendel wrote:
...
Since Haskell features algebraic data types, and a reasonable flexible syntax, you do not need to do any parsing. Instead, you can write down the AST of the embedded language directly as part of your Haskell program. But you have to write an evaluator. With pattern matching, that is often very easy, though.
looks like I'm off to read about Template Haskell.
And it looks like: http://www.haskell.org/tmrwiki/TemplateHaskell#head-96ad34fffdb541d4e334edee... is a pretty good starting point. To write a symbolic differentiator in haskell, with evaluable results, this looks to be the way to start. A
participants (6)
-
Alex Shearn
-
Andrew Sackville-West
-
Brandon S. Allbery KF8NH
-
Brent Yorgey
-
Tillmann Rendel
-
Tony Hannan