为什么Haskell有非严格的函数(语义)?

编程入门 行业动态 更新时间:2024-10-27 17:24:16
本文介绍了为什么Haskell有非严格的函数(语义)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

根据这篇关于 haskell中的指称语义的文章所有类型都有底,如果一个函数f:A-> B是严格的,如果它将A类型的底部映射到B类型的底部,则称其为 non-strict 。

(这让人联想到态射保持基点的尖端类别)。

为什么Haskell没有 - 严格的函数,而标准的ML没有?

解决方案

每个带递归的至少一个非严格函数,通常以条件形式( if-then-else )。否则,所有的递归都会表示底部(非终止)。尽管非严格功能是必不可少的,但是,大多数这些语言不允许你自己定义!有些语言通过提供宏来弥补这一限制 - 这是一种类似于函数的机​​制,可以转换语法而不是值。

According to this article on denotational semantics in haskell All types have bottom, and a function f:A->B is strict if it maps the bottom of type A to the bottom of type B, it is called non-strict other-wise.

(This is reminiscent of a pointed category where morphisms preserve the basepoint).

Why does Haskell have non-strict functions, whereas Standard ML doesn't?

解决方案

Every programming language with recursion has at least one non-strict function, often in the form of a conditional (if-then-else). Otherwise all recursions would denote bottom (non-termination). Essential as non-strict functions are, however, most of these languages do not let you define your own! Some languages make up for this limitation by offering macros--a somewhat function-like mechanism that transforms syntax instead of values.

更多推荐

为什么Haskell有非严格的函数(语义)?

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

发布评论

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

>www.elefans.com

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