Haskell 程序可以表示为 Lisp S 表达式吗?

发布于 2024-11-13 03:45:06 字数 117 浏览 5 评论 0原文

这对于遗传编程很有用,遗传编程通常使用 Lisp 子集作为程序的表示。

我在网上找到了一个叫做 Liskell(Lisp 语法,里面有 Haskell)的东西,但是链接已损坏,我找不到它的论文......

This would be useful for genetic programming, which usually use a Lisp subset as representation for programs.

I've found something called Liskell (Lisp syntax, Haskell inside) on the web, but the links are broken and I can't find the paper on it...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

温柔嚣张 2024-11-20 03:45:06

查看 Lisk,它旨在修复作者的问题与利斯克尔抱怨。

在业余时间,我正在开发一个名为 Lisk 的项目。使用 GHC 的 -pgmF 选项,您可以为 GHC 提供一个程序名称,在 GHC 编译文件之前调用该程序名称来预处理文件。它也适用于 GHCi 和导入。你可以像这样使用它:

{-# 选项 -F -pgmF lisk #-}
(模块错误
  (导入系统.环境)

  (:: 主要(io()))
  (= main(>>= get-args(.print fib read head)))

  (:: 测试 (-> :string (, :int :string)))
  (= 测试 (, 1))

  (:: fib (-> :int :int))
  (= 纤维 0 0)
  (= 谎言 1 1)
  (= fib n (+ (fib (- n 1)))
              (fib (- n 2)))))

来源位于此处

另外,如果您实际上并不关心 Haskell 而只是想要它的一些功能,您可能需要查看 Qi (或其后继者 Shen),它具有 s 表达式语法,与许多现代函数式编程功能类似哈斯克尔。

Check out Lisk, which was designed to fix the author's gripes with Liskell.

In my spare time I’m working on a project called Lisk. Using the -pgmF option for GHC, you can provide GHC a program name that is called to preprocess the file before GHC compiles it. It also works in GHCi and imports. You use it like this:

{-# OPTIONS -F -pgmF lisk #-}
(module fibs
  (import system.environment)

  (:: main (io ()))
  (= main (>>= get-args (. print fib read head)))

  (:: test (-> :string (, :int :string)))
  (= test (, 1))

  (:: fib (-> :int :int))
  (= fib 0 0)
  (= fib 1 1)
  (= fib n (+ (fib (- n 1))
              (fib (- n 2)))))

The source is here.

Also, if you don't actually care about Haskell and just want some of its features, you might want to check out Qi (or its successor, Shen), which has s-expression syntax with many modern functional-programming features similar to Haskell.

隱形的亼 2024-11-20 03:45:06

您可能对我一直在从事的一个项目感兴趣,husk 方案

基本上它会让你从 Haskell 调用Scheme代码(S表达式),反之亦然。因此,您可以在程序中混合该代码,然后当您想在 Haskell 端执行某些操作时,将 s 表达式作为本机 Haskell 数据类型进行处理。

不管怎样,它可能对你有用,也可能没用——看看然后自己决定。

You might be interested in a project I have been working on, husk scheme.

Basically it will let you call into Scheme code (S-expressions) from Haskell, and vice-versa. So you can intermingle that code within your program, and then process the s-expressions as native Haskell data types when you want to do something on the Haskell side.

Anyway, it may be useful to you, or not - have a look and decide for yourself.

梦纸 2024-11-20 03:45:06

在大多数遗传编程软件中,程序被表示为抽象语法树(AST),并直接以这种形式进行评估。仅当程序作为源代码输出时,Lisp S 表达式语法才明显。您是否考虑过仅修改所选软件中的输出模块以从 AST 生成 Haskell 源代码?

In most genetic programming software, programs are represented as abstract syntax trees (AST) which are evaluated directly in that form. The Lisp S-expression syntax is only apparent when the programs are output as source code. Have you considered just modifying the output module in your chosen software to produce Haskell source code from the ASTs instead?

橘味果▽酱 2024-11-20 03:45:06

显而易见的答案是“是”——这并不奇怪,因为 S 表达式的目的是作为一个简单的 & 表达式。解析代码的统一表示。问题是像 Haskell 或 ML 这样的语言往往会遇到一些问题。我曾经做过类似 OCaml 的事情(滥用 CamlP4 并编写了一些函数,将 P4 AST 转换为某种类似 sexpr 的表示),当您遇到具有不同类型的类似 AST 节点时,乐趣就开始了,因为它们并不是真正的相同...例如,有函数应用程序,有一种类似的形式用于模式,还有另一种形式用于类型表达式。

我的猜测是,尝试以这种方式进行遗传编程很可能会遇到太多没有任何意义的垃圾程序。但这对于任何静态类型语言来说也不足为奇——动态类型语言将允许更多垃圾进入。出于人工智能之外的原因,将这两个世界的 WRT 与遗传编程进行比较可能会很有趣......

The obvious answer is "yes" -- unsurprising given that S-expressions were intended as a simple & uniform representation of parsed code. The thing is that languages like Haskell or ML tend to have some problems with that. I once did something similar to OCaml (abused CamlP4 and wrote some function that translates the P4 AST into some sexpr-like representation), and the fun begins when you run into similar kinds of AST nodes that have different types because they're not really the same... For example, there's function application, and there's a similar form that is used in patterns, and yet another form that is used in type expressions.

My guess is that trying to do genetic programming this way is likely to suffer from too much junk programs that don't have any meaning. But that's unsurprising too for any statically typed language -- a dynamically typed language will allow more junk in. Comparing the two worlds WRT to genetic programming might be interesting for reasons beyond the AI...

巴黎夜雨 2024-11-20 03:45:06

Liskell 论文位于 http://clemens.endorphin.org/ILC07-Liskell-draft。 pdf 和 liskell.org 网站似乎仍然正常运行。

The Liskell paper is at http://clemens.endorphin.org/ILC07-Liskell-draft.pdf and the liskell.org site seems to still be up in general.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文