1
- module Examples where
1
+ module Examples where
2
2
import Control.Monad.Eff.Console (CONSOLE ())
3
3
4
4
import Data.Either (either )
@@ -13,55 +13,55 @@ module Examples where
13
13
import Control.Monad.Eff.Class (liftEff )
14
14
import Control.Monad.Eff.Exception (error )
15
15
import Control.Monad.Error.Class (throwError )
16
-
16
+
17
17
type Test a = forall e. Aff (console :: CONSOLE | e ) a
18
18
type TestAVar a = forall e. Aff (console :: CONSOLE , avar :: AVAR | e ) a
19
19
20
- test_sequencing :: Int -> Test _
20
+ test_sequencing :: Int -> Test String
21
21
test_sequencing 0 = print " Done"
22
22
test_sequencing n = do
23
23
later' 100 (print (show (n / 10) ++ " seconds left "))
24
24
test_sequencing (n - 1)
25
25
26
- test_pure :: Test _
26
+ test_pure :: Test String
27
27
test_pure = do
28
- pure unit
28
+ pure unit
29
29
pure unit
30
30
pure unit
31
31
print " Success: Got all the way past 4 pures"
32
32
33
- test_attempt :: Test _
33
+ test_attempt :: Test String
34
34
test_attempt = do
35
35
e <- attempt (throwError (error "Oh noes!"))
36
36
either (const $ print "Success : Exception caught ") (const $ print "Failure : Exception NOT caught !!!") e
37
37
38
- test_apathize :: Test _
38
+ test_apathize :: Test String
39
39
test_apathize = do
40
40
apathize $ throwError (error "Oh noes !")
41
41
print " Success: Exceptions don't stop the apathetic"
42
42
43
- test_putTakeVar :: TestAVar _
43
+ test_putTakeVar :: TestAVar String
44
44
test_putTakeVar = do
45
45
v <- makeVar
46
46
forkAff (later $ putVar v 1.0)
47
- a <- takeVar v
47
+ a <- takeVar v
48
48
print ("Success : Value " ++ show a )
49
49
50
- test_killFirstForked :: Test _
51
- test_killFirstForked = do
50
+ test_killFirstForked :: Test String
51
+ test_killFirstForked = do
52
52
c <- forkAff (later' 100 $ pure "Failure : This should have been killed !")
53
53
b <- c `cancel` (error "Just die ")
54
54
print (if b then "Success : Killed first forked " else "Failure : Couldn't kill first forked ")
55
55
56
56
57
- test_killVar :: TestAVar _
57
+ test_killVar :: TestAVar String
58
58
test_killVar = do
59
59
v <- makeVar
60
60
killVar v (error "DOA ")
61
61
e <- attempt $ takeVar v
62
62
either (const $ print "Success : Killed queue dead ") (const $ print "Failure : Oh noes , queue survived !") e
63
63
64
- test_finally :: TestAVar _
64
+ test_finally :: TestAVar String
65
65
test_finally = do
66
66
v <- makeVar
67
67
finally
@@ -76,47 +76,47 @@ module Examples where
76
76
print $ if n1 + n2 + n3 == 42 then " Success: effects amount to 42."
77
77
else " Failure: Expected 42."
78
78
79
- test_parRace :: TestAVar _
79
+ test_parRace :: TestAVar String
80
80
test_parRace = do
81
- s <- runPar (Par (later' 100 $ pure "Success: Early bird got the worm") <|>
81
+ s <- runPar (Par (later' 100 $ pure "Success: Early bird got the worm") <|>
82
82
Par (later' 200 $ pure "Failure: Late bird got the worm"))
83
83
print s
84
84
85
- test_parRaceKill1 :: TestAVar _
85
+ test_parRaceKill1 :: TestAVar String
86
86
test_parRaceKill1 = do
87
- s <- runPar (Par (later' 100 $ throwError (error ("Oh noes!"))) <|>
87
+ s <- runPar (Par (later' 100 $ throwError (error ("Oh noes!"))) <|>
88
88
Par (later' 200 $ pure "Success : Early error was ignored in favor of late success "))
89
89
print s
90
90
91
- test_parRaceKill2 :: TestAVar _
91
+ test_parRaceKill2 :: TestAVar String
92
92
test_parRaceKill2 = do
93
- e <- attempt $ runPar (Par (later' 100 $ throwError (error ("Oh noes!"))) <|>
93
+ e <- attempt $ runPar (Par (later' 100 $ throwError (error ("Oh noes!"))) <|>
94
94
Par (later' 200 $ throwError (error ("Oh noes!"))))
95
95
either (const $ print "Success : Killing both kills it dead ") (const $ print "Failure : It's alive !!!") e
96
96
97
- test_semigroupCanceler :: Test _
98
- test_semigroupCanceler =
99
- let
97
+ test_semigroupCanceler :: Test String
98
+ test_semigroupCanceler =
99
+ let
100
100
c = Canceler (const (pure true)) <> Canceler (const (pure true))
101
- in do
101
+ in do
102
102
v <- cancel c (error "CANCEL ")
103
- print (if v then "Success : Canceled semigroup composite canceler "
103
+ print (if v then "Success : Canceled semigroup composite canceler "
104
104
else "Failure : Could not cancel semigroup composite canceler ")
105
105
106
- test_cancelLater :: TestAVar _
106
+ test_cancelLater :: TestAVar String
107
107
test_cancelLater = do
108
108
c <- forkAff $ (do pure "Binding "
109
109
_ <- later' 100 $ print ("Failure: Later was not canceled!")
110
110
pure "Binding ")
111
111
v <- cancel c (error "Cause ")
112
112
print (if v then "Success : Canceled later " else "Failure : Did not cancel later ")
113
113
114
- test_cancelPar :: TestAVar _
114
+ test_cancelPar :: TestAVar String
115
115
test_cancelPar = do
116
116
c <- forkAff <<< runPar $ Par (later' 100 $ print "Failure : #1 should not get through ") <|>
117
117
Par (later' 100 $ print "Failure : #2 should not get through ")
118
118
v <- c `cancel` (error "Must cancel ")
119
- print (if v then "Success : Canceling composite of two Par succeeded "
119
+ print (if v then "Success : Canceling composite of two Par succeeded "
120
120
else "Failure : Canceling composite of two Par failed ")
121
121
122
122
main = launchAff $ do
0 commit comments