Changeset 12104 for src/Pugs/Val

Show
Ignore:
Timestamp:
08/11/06 09:11:00 (2 years ago)
Author:
gaal
Message:

* PureNum? encapsulates both floating-point and fractional values
* add Val.Sig (not compiled at the moment, waiting on circularity saw)

Location:
src/Pugs/Val
Files:
1 added
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Val/Num.hs

    r12044 r12104  
    44import qualified Data.ByteString.Char8 as Char8 
    55 
    6 instance ((:>:) PureNum) Double where cast = MkNum 
    7 instance ((:<:) PureNum) Double where castBack (MkNum i) = i 
     6instance ((:>:) PureNum) Double where cast = NDouble 
     7instance ((:<:) PureNum) Double where 
     8    castBack (NDouble   x) = x 
     9    castBack (NRational x) = fromRational x 
    810 
    9 instance ((:>:) PureNum) Int where cast = MkNum . fromIntegral 
     11instance ((:>:) PureNum) Rational where cast = NRational 
     12instance ((:<:) PureNum) Rational where 
     13    castBack (NDouble   x) = toRational x 
     14    castBack (NRational x) = x 
    1015 
    11 newtype PureNum = MkNum Double 
    12     deriving (Typeable, Show, Eq, Ord, Data, (:>:) Double, (:<:) Double) 
     16instance ((:>:) PureNum) Int where cast = NRational . fromIntegral 
     17 
     18data PureNum 
     19    = NDouble   !Double              -- change to "!NativeDouble" 
     20    | NRational !Rational 
     21    deriving (Typeable, Show, Eq, Ord, Data) 
    1322 
    1423{- regretfully, I couldn't find a way to put this here w/o circularity.