有限制类型的语言吗?

编程入门 行业动态 更新时间:2024-10-27 07:30:35
本文介绍了有限制类型的语言吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有一种类型化的编程语言,我可以像下面两个例子那样限制类型?

Is there a typed programming language where I can constrain types like the following two examples?

  • 概率是一个浮动

  • A Probability is a floating point number with minimum value 0.0 and maximum value 1.0. type Probability subtype of float where max_value = 0.0 min_value = 1.0

  • 离散概率分布是一张图, :键应该都是相同的类型,值都是概率,值的总和= 1.0。

  • A Discrete Probability Distribution is a map, where: the keys should all be the same type, the values are all Probabilities, and the sum of the values = 1.0.

    type DPD<K> subtype of map<K, Probability> where sum(values) = 1.0

  • 据我所知,Haskell或Agda是不可能的。

    As far as I understand, this is not possible with Haskell or Agda.

    推荐答案

    称为优化类型。

    这是可以在Agda中定义概率: Prob.agda

    It's possible to define Probability in Agda: Prob.agda

    具有和条件的概率质量函数类型在第264行定义。

    The probability mass function type, with sum condition is defined at line 264.

    有些语言比Agda有更直接的优化类型,例如 ATS

    There are languages with more direct refinement types than in Agda, for example ATS

    更多推荐

    有限制类型的语言吗?

    本文发布于:2023-10-17 11:03:09,感谢您对本站的认可!
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:类型   语言

    发布评论

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

    >www.elefans.com

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