Digital Domains at Haskell

Haskell more mathematical than many languages, because of the lambda calculus, but I think that for the number of domains is incomplete: we have Integerand Float, for example, but not Positiveor Negative, or [1..5]as a domain. This sometimes makes functions unsafe, while the compiler could catch a type error. For example: 5mod only 0outputs *** Exception: divide by zeroat run time. mod :: Integral a => a -> a -> abut we could have something like mod :: Integral a, a != 0 => a -> a -> a; something like a guard or interval or other type of data ... In the game, I want my character to have a positive number in my life. Or from 0 to 100, not under, not on top. When he gets hit, I need to call ugly positive x = if x > 0 then x else 0. Even C has signedand unsigned.

Is it a weakness or reasons why there are no "interval" domains? Is there a package fixing this?

+5
source share
2 answers

You can create such classes, but perhaps the reason they were not included in Haskell was because people couldn't find a way to make them often useful.

Obviously, you want a subtraction with your class, but you also want it to be closed.

Something like this maybe?

NonNegative x - NonNegative y = NonNegative (max (x - y) 0)

But then the identity is x - y + y == xnot fulfilled.

Haskell, 'Numeric Prelude'. Haskell , Prelude , , , - .

+6

, , , , Agda, Idris Coq.

, , , . , mod, 0. . , , -, "" , 0, , , , , - ? - , , 0, mod. Haskell ( , ), .

+6
source

All Articles