blob: a1badf15fa9230b61e109bfa2e71e8b4302b7bdd (
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
34
|
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnboxedTuples #-}
module Main where
import GHC.Exts
import GHC.Types
import GHC.Num
data T = T Word8#
instance Num T where
fromInteger i = T (wordToWord8# (integerToWord# i))
instance Eq T where
(==) (T a) (T b) = isTrue# (a `eqWord8#` b)
main :: IO ()
main = do
let !addr = "\0\1\2\3\4\5\6\7\8"#
w8 <- IO (\s -> case readWord8OffAddr# (plusAddr# addr 5#) 0# s of
(# s', w8 #) -> (# s', T w8 #))
-- w8 must be small enough for one of the branch to be taken.
-- we need several alternatives for a jump table to be used
print $ case w8 of
0 -> 1000
1 -> 1001
2 -> 1002
3 -> 1003
4 -> 1004
5 -> 1005
6 -> 1006
_ -> 1010
|