home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / MacHaskell 2.2 / progs / lib / hbc / NativeTest.hs < prev    next >
Encoding:
Text File  |  1994-09-27  |  1.5 KB  |  62 lines  |  [TEXT/YHS2]

  1. module NativeTest where
  2.  
  3. import Native
  4.  
  5.  
  6. -- stuff to test reading and writing from Bytes
  7.  
  8. x1 :: Char
  9. x1 = readB (showBytes '1' [])
  10.  
  11. x2 :: Int
  12. x2 = readB (showBytes (2::Int) [])
  13.  
  14. x3 :: Float
  15. x3 = readB (showBytes (3::Float) [])
  16.  
  17. x4 :: Double
  18. x4 = readB (showBytes (4::Double) [])
  19.  
  20. x5 :: (Int, Float)
  21. x5 = readB (showBytes ((5::Int), (5::Float)) [])
  22.  
  23. x6 :: (Char, Int, Float)
  24. x6 = readB (showBytes ('6', (6::Int), (6::Float)) [])
  25.  
  26. x7 :: [Int]
  27. x7 = readB (showBytes ([1,2,3,4,5,6,7]::[Int]) [])
  28.  
  29.  
  30.  
  31. -- stuff to test reading and writing from ByteFiles
  32.  
  33. x = openOutputByteFile "foo.out" >>= \f ->
  34.     showByteFile '1' f >>
  35.     showByteFile (2::Int) f >>
  36.     showByteFile (3::Float) f >>
  37.     showByteFile (4::Double) f >>
  38.     showByteFile ((5::Int), (5::Float)) f >>
  39.     showByteFile ('6', (6::Int), (6::Float)) f >>
  40.     showByteFile ([1,2,3,4,5,6,7]::[Int]) f >>
  41.     closeByteFile f
  42.  
  43. y = openInputByteFile "foo.out" >>= \f ->
  44.     readByteFile f >>= \x1 ->
  45.     readByteFile f >>= \x2 ->
  46.     readByteFile f >>= \x3 ->
  47.     readByteFile f >>= \x4 ->
  48.     readByteFile f >>= \x5 ->
  49.     readByteFile f >>= \x6 ->
  50.     readByteFile f >>= \x7 ->
  51.     closeByteFile f >>
  52.     let g (Just x) = x
  53.         g _      = error "readByteFile failed"
  54.         y1 = (g x1) :: Char
  55.         y2 = (g x2) :: Int
  56.         y3 = (g x3) :: Float
  57.         y4 = (g x4) :: Double
  58.         y5 = (g x5) :: (Int,Float)
  59.         y6 = (g x6) :: (Char,Int,Float)
  60.         y7 = (g x7) :: [Int]
  61.     in putText (y1, y2, y3, y4, y5, y6, y7)
  62.