summaryrefslogtreecommitdiff
path: root/testsuite/tests/typecheck/should_run/TestTypeableBinary.hs
blob: e427c1372596a4409b790cc2814fe010ed3129a8 (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 MagicHash #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}

import qualified Data.ByteString as BS
import Type.Reflection
import Data.Binary
import GHCi.TH.Binary ()

import GHC.Exts
import Data.Kind
import Data.Proxy

testRoundtrip :: Typeable a => TypeRep a -> IO ()
testRoundtrip rep
  | rep /= rep' = putStrLn $ "bad: " ++ show rep ++ " /= " ++ show rep'
  | otherwise   = putStrLn $ "good: " ++ show rep
  where
    rep' = decode (encode rep)

main :: IO ()
main = do
    testRoundtrip (typeRep :: TypeRep Int)
    testRoundtrip (typeRep :: TypeRep Int#)
    testRoundtrip (typeRep :: TypeRep IO)
    testRoundtrip (typeRep :: TypeRep Maybe)
    testRoundtrip (typeRep :: TypeRep TYPE)
    testRoundtrip (typeRep :: TypeRep RuntimeRep)
    testRoundtrip (typeRep :: TypeRep 'IntRep)
    testRoundtrip (typeRep :: TypeRep (->))
    testRoundtrip (typeRep :: TypeRep (Proxy Int))
    testRoundtrip (typeRep :: TypeRep (Proxy Int#))
    testRoundtrip (typeRep :: TypeRep Type)
    testRoundtrip (typeRep :: TypeRep (Int -> Int))
    testRoundtrip (typeRep :: TypeRep 5)
    testRoundtrip (typeRep :: TypeRep "hello world")
    testRoundtrip (typeRep :: TypeRep ('Just 5))