[Haskell-fr] Re: inférence

Dan Weston westondan at imageworks.com
Thu Sep 13 19:11:39 EDT 2007


Dupont Corentin wrote:
> J'ai d'autres questions bêtes:
> 
> - je n'ai pas trouvé d'opérateur / comme ceci:
> (/) :: a -> a -> Maybe a
> 
> Pourtant il me semble que ce serait une bonne utilisation de Maybe
> pour la division par zero?

Ta question n'est nullement bête!

La division par zéro n'est pas indéfinie en Haskell (IEEE), mais plutôt 
infinie:

>Prelude> 3/0
Infinity

La plupart du temps ça correspond à ce que tu veux (bien que 
mathématiquement soupçonneux):

Prelude> exp (-1/0)
0.0

Prelude> atan (1/0)
1.5707963267948966

Prelude> atan (-1/0)
-1.5707963267948966

Le type Double contient l'infini comme valeur tout à fait respectable 
(au moins pour les architectures qui supportent le format IEEE), comme 
prevue dans:

class (RealFrac a, Floating a) => RealFloat a where
   floatRadix :: a -> Integer
   floatDigits :: a -> Int
   floatRange :: a -> (Int, Int)
   decodeFloat :: a -> (Integer, Int)
   encodeFloat :: Integer -> Int -> a
   exponent :: a -> Int
   significand :: a -> a
   scaleFloat :: Int -> a -> a
   isNaN :: a -> Bool
   isInfinite :: a -> Bool
   isDenormalized :: a -> Bool
   isNegativeZero :: a -> Bool
   isIEEE :: a -> Bool
   atan2 :: a -> a -> a

Dan



More information about the Haskell-fr mailing list