diff options
author | David Terei <davidterei@gmail.com> | 2011-07-20 17:01:04 -0700 |
---|---|---|
committer | David Terei <davidterei@gmail.com> | 2011-07-20 17:01:04 -0700 |
commit | fd4250b4596b581e9e80d0072b05ecf4ca4ebc77 (patch) | |
tree | 43df812b5a41881075dc73ee58372d42a626076b /testsuite/tests/safeHaskell/safeLanguage/SafeLang14.hs | |
parent | 96de88d51300bf5eab5388dc7cf61aa26f6dc7a0 (diff) | |
download | haskell-fd4250b4596b581e9e80d0072b05ecf4ca4ebc77.tar.gz |
Add tests for Safe Haskell Typeable instances feature
Diffstat (limited to 'testsuite/tests/safeHaskell/safeLanguage/SafeLang14.hs')
-rw-r--r-- | testsuite/tests/safeHaskell/safeLanguage/SafeLang14.hs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/testsuite/tests/safeHaskell/safeLanguage/SafeLang14.hs b/testsuite/tests/safeHaskell/safeLanguage/SafeLang14.hs new file mode 100644 index 0000000000..9be68a3abb --- /dev/null +++ b/testsuite/tests/safeHaskell/safeLanguage/SafeLang14.hs @@ -0,0 +1,41 @@ +{-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-} +-- | This shows how to use typeable to perform unsafe +-- casts. Basically its an example of what Safe Haskell +-- should disallow. SafeLang14 will do that. +module Main where + +import SafeLang13_A +import Data.Typeable + +data H = H String deriving (Typeable, Show) + +data G = G Int deriving (Show) + +instance Typeable G where + typeOf _ = typeOf (undefined :: H) + +instance Typeable P where + typeOf _ = typeOf (undefined :: G) + +{- +deriving instance Typeable G + +deriving instance Typeable P +-} + +main = do + let h = H "Hello World" + g = G 1 +-- Just h' = (cast h) :: Maybe G + Just p' = (cast p) :: Maybe G + Just px = (cast $ incrG p') :: Maybe P + putStrLn $ show h + putStrLn $ show g +-- putStrLn $ show h' + putStrLn $ showP p + putStrLn $ show p' + putStrLn $ showP px + +incrG :: G -> G +incrG (G n) = G $ n + 1 + |