Suppress warnings when compiling primitive and random
[ghc.git] / testsuite / tests / deriving / should_compile / T8138.hs
1 {-# LANGUAGE ScopedTypeVariables #-}
2
3 module Main where
4
5 import Control.Monad.ST
6 import Data.Primitive
7
8 main :: IO ()
9 main = do
10 let xs :: [Float] = runST $ do
11 barr <- mutableByteArrayFromList [1..fromIntegral n::Float]
12 peekByteArray n barr
13 print xs
14 where
15 n = 13
16
17 mutableByteArrayFromList :: forall s a . (Prim a)
18 => [a]
19 -> ST s (MutableByteArray s)
20 mutableByteArrayFromList xs = do
21 arr <- newByteArray (length xs*sizeOf (undefined :: a))
22 loop arr 0 xs
23 return arr
24 where
25 loop :: MutableByteArray s -> Int -> [a] -> ST s ()
26 loop _ _ [] = return ()
27
28 loop arr i (x : xs) = do
29 writeByteArray arr i x
30 loop arr (i+1) xs
31
32 peekByteArray :: (Prim a)
33 => Int
34 -> MutableByteArray s
35 -> ST s [a]
36 peekByteArray n arr =
37 loop 0 arr
38 where
39 loop :: (Prim a)
40 => Int
41 -> MutableByteArray s
42 -> ST s [a]
43 loop i _ | i >= n = return []
44
45 loop i arr = do
46 x <- readByteArray arr i
47 xs <- loop (i+1) arr
48 return (x : xs)