summaryrefslogtreecommitdiff
path: root/testsuite/tests/unboxedsums/unboxedsums8.hs
blob: 07ef122b696e811d5b4bb8880b01c7bb028a2d9c (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
35
36
37
{-# LANGUAGE UnboxedSums, UnboxedTuples, MagicHash #-}

module Main where

import GHC.Prim
import GHC.Types

type Sum1 = (# (# Int#, Int #) | (# Int#, Int# #) | (# Int, Int# #) #)

{-# NOINLINE showSum1 #-}
showSum1 :: Sum1 -> String
showSum1 (# p1 | | #) = showP1 p1
showSum1 (# | p2 | #) = showP2 p2
showSum1 (# | | p3 #) = showP3 p3

{-# NOINLINE showP1 #-}
showP1 :: (# Int#, Int #) -> String
showP1 (# i1, i2 #) = show (I# i1) ++ show i2

{-# NOINLINE showP2 #-}
showP2 :: (# Int#, Int# #) -> String
showP2 (# i1, i2 #) = show (I# i1) ++ show (I# i2)

{-# NOINLINE showP3 #-}
showP3 :: (# Int, Int# #) -> String
showP3 (# i1, i2 #) = show i1 ++ show (I# i2)

main :: IO ()
main = do
    putStrLn (showSum1 s1)
    putStrLn (showSum1 s2)
    putStrLn (showSum1 s3)
  where
    s1, s2, s3 :: Sum1
    s1 = (# (# 123#, 456 #) | | #)
    s2 = (# | (# 876#, 543# #) | #)
    s3 = (# | | (# 123, 456# #) #)