seq在haskell中代表什么 [英] what does seq stand for in haskell
问题描述
我是Haskell的新手,刚刚来到懒惰的世界.我读到 seq
函数非常特殊,因为它强制使用严格的评估以便在某些情况下更有效.但我只是找不到 seq
的字面意思.也许严格评估Q * ???
I am new to haskell, and have just come to the lazy world proramming. I read that the seq
function is very special because it forces to use a strict evaluation in order to be more efficient in some cases. But I just can't find what seq
stand for literally. Maybe Strict Evaluation Q*???
推荐答案
seq
在返回第二个参数之前先评估其第一个参数.通常引入它是为了避免不必要的懒惰,从而提高性能.强制对功能进行评估.
seq
evaluates its first argument before returning the second one. It is usually introduced to improve performance by avoiding unneeded laziness. It forces evaluation of the function.
seq :: a -> b -> b
seq _ y = y
来自 prelude.hs
此函数定义包装在
#ifdef __HADDOCK __
中,因此它将只能由haddock(文档工具)编译,而不能由实际的编译器!真实"序列在GHC.Prim中定义为
This function definition is wrapped in
#ifdef __HADDOCK__
so it will only be compiled by haddock (the documentation tool), not by the actual compiler! The 'real' seq is defined in GHC.Prim as
seq :: a -> b -> b;
seq = let x = x in x.
这只是一个虚拟定义.基本上seq是特殊语法特别由编译器处理.您写了'seq评估其第一个参数"-但第一个定义显然没有做到这一点.
This is only a dummy definition. Basically seq is specially syntax handled particularly by the compiler. You wrote 'seq evaluates its first argument' - but first definition obviously does not do this.
通过 user2407038
更多阅读内容:
这篇关于seq在haskell中代表什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!