summaryrefslogtreecommitdiff
path: root/libraries/base/tests/isValidNatural.hs
blob: d0ae899de84c9ac32e8cc1aa662997ab87622372 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnboxedTuples #-}

import GHC.Num.Natural
import GHC.Num.BigNat
import GHC.Exts
import GHC.IO

main = do
   let
      maxWord = fromIntegral (maxBound :: Word)
      invalid = NB (bigNatOne# (# #)) -- 1 would fit into the NS constructor.

   -- byteArray whose size is not a multiple of Word size
   invalid2 <- IO $ \s -> case newByteArray# 27# s of
                           (# s', mba #) -> case unsafeFreezeByteArray# mba s' of
                              (# s'', ba #) -> (# s'', NB ba #)

   print $ map naturalCheck [0, 1, maxWord, maxWord + 1, invalid, invalid2]