summaryrefslogtreecommitdiff
path: root/libraries/base/tests/data-fixed-show-read.hs
blob: 8766f0ae0c531aaeaea168d6e950fce1aabb274a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

module Main (main) where

import Data.Fixed

data B7

instance HasResolution B7 where
  resolution _ = 128

main :: IO ()
main = do doit 38.001
          doit 38.009
          doit 38.01
          doit 38.09
          print (read "38" :: Centi)
          doit (-38.001)
          doit (-38.009)
          doit (-38.01)
          doit (-38.09)
          print (read "-38" :: Centi)
          print (read "0.008" :: Fixed B7)
          print (read "-0.008" :: Fixed B7)
          print $ show (Just (-1 :: Milli))
          print $ show (Just (1 :: Milli))
          print ((read $ show (Just (-1 :: Deci))) :: Maybe Deci)
          print ((read $ show (Just (1 :: Deci))) :: Maybe Deci)

doit :: Centi -> IO ()
doit c = do let s = show c
                r = read s :: Centi
            putStrLn s
            print r