为什么Haskell有非严格的函数(语义)? [英] Why does Haskell have non-strict functions (semantics)?

查看:130
本文介绍了为什么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有非严格的函数(语义)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆