Haskell中的monadic IO构造只是一个约定,还是有一个实现原因呢?
你能不能只用FFI进入libc.so而不是你的IO,并跳过IO Monad组件?
无论如何它会起作用,或者结果是不确定的,因为Haskell评估懒惰或其他东西,比如GHC是IO Monad的模式匹配,然后以特殊方式或其他方式处理它.
真正的原因是什么?最后你最终会产生副作用.那么为什么不这么简单呢?
似乎直到最近几年,将额外类型传递给函数的通常方法是执行类似的操作
f (undefined :: T)
Run Code Online (Sandbox Code Playgroud)
Kiselyov和Shan甚至在他们的经典论文中使用了这种方法,该论文基于类的反思,激发了这个reflection方案.他们通过注意到从未检查过伪造的价值来原谅明显的丑陋.并且出现了一个稍微不那么丑陋的化身Data.Bits.finiteBitSize,它取了一个它忽略的值来获得它的类型.
然后有人想出代理习语,一切都改变了.现在我们总能看到更令人满意的
f (Proxy :: Proxy T)
Run Code Online (Sandbox Code Playgroud)
(在标准代码-GHC类型的应用程序是另一个故事).
是谁想出来的?这是第一次出现在某个地方的代码还是纸上?
我的 Haskell 文件中有以下功能:
notFound :: () -> IO ()
notFound = putStr "Sorry, your command could not be found"
Run Code Online (Sandbox Code Playgroud)
该函数无法编译。这是我得到的编译错误:
todos.hs:27:12:
Couldn't match expected type ‘() -> IO ()’ with actual type ‘IO ()’
Possible cause: ‘putStr’ is applied to too many arguments
In the expression: putStr "Sorry, your command could not be found"
In an equation for ‘notFound’:
notFound = putStr "Sorry, your command could not be found"
Run Code Online (Sandbox Code Playgroud)
但以下功能确实如此:
notFound :: IO ()
notFound = putStr "Sorry, your command …Run Code Online (Sandbox Code Playgroud) 该类型和功能演讲呈现功能:
f44 :: () -> Integer
f44 () = 44
Run Code Online (Sandbox Code Playgroud)
我键入以下内容:
ghci> let f () = 5
ghci> f ()
5
Run Code Online (Sandbox Code Playgroud)
但是,我被迷惑()在let f ().通常,作为初学者,我在函数名后面看到了一个不可变的变量,即f.
什么时候被()列出let f ...?在函数应用程序中使用它时怎么样f ()?