seq在haskell中代表什么

编程入门 行业动态 更新时间:2024-10-25 01:23:07
本文介绍了seq在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

更多阅读内容:

  • 在HaskellWiki上
  • 真实世界的Haskell.Chapter 25.分析和优化
  • 在StackOverflow上
  • 使Haskell程序更快,更小
  • 如何避免seq

更多推荐

seq在haskell中代表什么

本文发布于:2023-11-25 02:40:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627992.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代表   seq   haskell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!