-
Notifications
You must be signed in to change notification settings - Fork 0
/
Unsafee.hs
56 lines (47 loc) · 1.01 KB
/
Unsafee.hs
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
{-# LANGUAGE MagicHash #-}
module Main where
import Unsafe.Coerce
import GHC.Exts
data CompactD = CA | CB | CC
deriving (Show)
data LargeD = LA | LB | LC | LD | LE | LF | LG | LH
deriving (Show)
data IntOrBool
= IBI# Int#
| IBB Bool
deriving (Show)
data MyInt = MyI# Int#
deriving (Show)
-- |
--
-- macOS: 10.14.3
-- CPU: Intel Core i7
-- Memory: 8GB DDR3
-- GHC: 8.6.3
-- Option: -O1
--
-- >>> main
-- 4315527696
-- MyI# 4315527696#
-- IBI# 4315527696#
-- 5764607523051092410
-- MyI# 5764607523051092410#
-- CB
-- 10
-- CB
-- CA
-- CA
--
main :: IO ()
main = do
print (unsafeCoerce False :: Int)
print (unsafeCoerce False :: MyInt)
print (unsafeCoerce False :: IntOrBool)
print (unsafeCoerce True :: Int)
print (unsafeCoerce True :: MyInt)
-- print (unsafeCoerce True :: IntOrBool) -- SIGSEGV
print (unsafeCoerce True :: CompactD)
print (unsafeCoerce (IBI# 10#) :: Int)
print (unsafeCoerce (IBB True) :: CompactD)
print (unsafeCoerce LA :: CompactD)
print (unsafeCoerce LD :: CompactD)