且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Haskell 中的 I/O 是函数式的吗?

更新时间:2023-02-13 22:31:37

虽然它看起来是一个过程程序,但上面的语法被翻译成一个函数式程序,如下所示:

While it appears to be a procedural program, the above syntax is translated into a functional program, like so:

   do { putStrLn "ABCDE" ; putStrLn "12345" }
=>
   IO ( s -> case (putStrLn "ABCDE" s) of
                  ( new_s, _ ) -> case (putStrLn "12345" new_s) of
                                      ( new_new_s, _) -> ((), new_new_s))

也就是说,一系列嵌套函数有一个独特的世界参数贯穿它们,程序性地"对原始函数的调用进行排序.此设计支持将命令式编程编码为函数式语言.

That is, a series of nested functions that have a unique world parameter threaded through them, sequencing calls to primitive functions "procedurally". This design supports an encoding of imperative programming into a functional language.

对基于此设计的语义决策的***介绍是 "The Awkward Squad" 论文,

The best introduction to the semantic decisions underlying this design is "The Awkward Squad" paper,