haskell - 为什么我们不用 LISP 语法编写 haskell 呢? (我们可以!)

标签 haskell macros lisp defmacro

关闭。这个问题是opinion-based .它目前不接受答案。












想改进这个问题?更新问题,以便 editing this post 可以用事实和引用来回答它.


2年前关闭。







Improve this question




它...有点工作你们(这绝对编译,改编自 https://hackage.haskell.org/package/scotty ):

main :: IO ()
main = (do
  (putStrLn "Starting Server....")
  (scotty 3000 (do
    (get "/hello/:name"
        (text ("hello " <> (param "name") <> "!")))

    (get "/users"
      (json allUsers))

    (get "/users/:id"
      (json (filter (matchesId (param "id")) allUsers))))))

(我不知道足够的 haskell 将 <> 转换为简单的括号,但聪明的人可以轻松。)

我们为什么要这样做?我们可以使用任何 lisp 宏引擎对 Haskell 进行预处理!琐碎!。

想象一下。 HASKELL 和 LISP 在一起。我们可以统治银河!

enter image description here

(我知道你的想法,但我实际上已经考虑过了:在这个例子中,Vader 是 Lisp,Luke 是 Haskell,Yoda 是 Alonzo Church)

(编辑“感谢所有回答和评论的人,我现在聪明多了。
我认为这种技术的最大问题还没有被提及,并且被 friend IRL 指出:如果你编写一些 lispy 预处理器,你会失去 IDE 和工具中的类型检查和语法突出显示和理解。这听起来像是我的一个硬传球。”

“我现在关注 https://github.com/finkel-lang/finkel 项目,这是我想要的 lisp 风格的 haskell 项目!”)

最佳答案

Haskell 的语法是 historically derived来自 ISWIM ,一种出现在 LISP 之后不久的语言,在 Peter J. Landin 的 1966 年文章 The Next 700 Programming Languages 中进行了描述.

第 6 节专门讨论与 LISP 的关系:

ISWIM can be looked on as an attempt to deliver LISP from its eponymous commitment to lists, its reputation for hand-to-mouth storage allocation, the hardware dependent flavor of its pedagogy, its heavy bracketing, and its compromises with tradition.



稍后在同一部分:

The textual appearance of ISWIM is not like LISP's S-expressions. It is nearer to LISP's M-expressions (which constitute an informal language used as an intermediate result in hand-preparing LISP programs). ISWIM has the following additional features: [...]



因此,有明确的意图偏离 LISP 语法,或者至少偏离 S 表达式。

关于haskell - 为什么我们不用 LISP 语法编写 haskell 呢? (我们可以!),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60464090/

相关文章:

c - 让 C 在 _Generic 中生成错误

c++ - __func__ 和 __PRETTY_FUNCTION__ 之间的东西?

haskell - 如何使用 Data.Binary 存储递归数据类型

haskell - 为什么我可以在单独的 IHaskell Notebook 单元格中更改变量的类型?

c++ - 是否可以将 C++ 实现为带有宏的 C 库?

python - 是否有可能*实时*修改 Python 代码(如 Lisp 或 Erlang)

functional-programming - 如何让我的大脑在 "lisp mode?"中移动

lisp - Lisp Scheme 中未绑定(bind)变量的错误

opengl - Haskell OpenGl 和 GLUT 模棱两可的发生

haskell - 当类型类只有一个时,具有 2 个参数的类型的类型类实例