blob: 9be68a3abb72f04d0832fcd5020289ff3246a1ec (
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
38
39
40
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
|