summaryrefslogtreecommitdiff
path: root/testsuite/tests/gadt/rw.hs
blob: 081dc3643bce62ea467acd45e74df937511fa8fe (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
{-# LANGUAGE GADTs #-}

module Main where

import Data.IORef

data T a where
  Li:: Int -> T Int
  Lb:: Bool -> T Bool
  La:: a -> T a

writeInt:: T a -> IORef a -> IO ()
writeInt v ref = case v of
                   ~(Li x) -> writeIORef ref (1::Int)

readBool:: T a -> IORef a -> IO ()
readBool v ref = case v of
                   ~(Lb x) ->
                       readIORef ref >>= (print . not)

tt::T a -> IO ()
tt v = case v of
         ~(Li x) ->  print "OK"

main = do
        tt (La undefined)
        ref <- newIORef undefined
        writeInt (La undefined) ref
        readBool (La undefined) ref