Is there a language with constrainable types?

后端 未结 8 1048
北海茫月
北海茫月 2020-12-09 15:59

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

  1. A Probability is a floating point number with minimum val

8条回答
  •  孤街浪徒
    2020-12-09 16:38

    Modula 3 has subrange types. (Subranges of ordinals.) So for your Example 1, if you're willing to map probability to an integer range of some precision, you could use this:

    TYPE PROBABILITY = [0..100]
    

    Add significant digits as necessary.

    Ref: More about subrange ordinals here.

提交回复
热议问题