1- module Examples where
1+ module Examples where
22 import Control.Monad.Eff.Console (CONSOLE ())
33
44 import Data.Either (either )
@@ -13,55 +13,55 @@ module Examples where
1313 import Control.Monad.Eff.Class (liftEff )
1414 import Control.Monad.Eff.Exception (error )
1515 import Control.Monad.Error.Class (throwError )
16-
16+
1717 type Test a = forall e. Aff (console :: CONSOLE | e ) a
1818 type TestAVar a = forall e. Aff (console :: CONSOLE , avar :: AVAR | e ) a
1919
20- test_sequencing :: Int -> Test _
20+ test_sequencing :: Int -> Test String
2121 test_sequencing 0 = print " Done"
2222 test_sequencing n = do
2323 later' 100 (print (show (n / 10) ++ " seconds left "))
2424 test_sequencing (n - 1)
2525
26- test_pure :: Test _
26+ test_pure :: Test String
2727 test_pure = do
28- pure unit
28+ pure unit
2929 pure unit
3030 pure unit
3131 print " Success: Got all the way past 4 pures"
3232
33- test_attempt :: Test _
33+ test_attempt :: Test String
3434 test_attempt = do
3535 e <- attempt (throwError (error "Oh noes!"))
3636 either (const $ print "Success : Exception caught ") (const $ print "Failure : Exception NOT caught !!!") e
3737
38- test_apathize :: Test _
38+ test_apathize :: Test String
3939 test_apathize = do
4040 apathize $ throwError (error "Oh noes !")
4141 print " Success: Exceptions don't stop the apathetic"
4242
43- test_putTakeVar :: TestAVar _
43+ test_putTakeVar :: TestAVar String
4444 test_putTakeVar = do
4545 v <- makeVar
4646 forkAff (later $ putVar v 1.0)
47- a <- takeVar v
47+ a <- takeVar v
4848 print ("Success : Value " ++ show a )
4949
50- test_killFirstForked :: Test _
51- test_killFirstForked = do
50+ test_killFirstForked :: Test String
51+ test_killFirstForked = do
5252 c <- forkAff (later' 100 $ pure "Failure : This should have been killed !")
5353 b <- c `cancel` (error "Just die ")
5454 print (if b then "Success : Killed first forked " else "Failure : Couldn't kill first forked ")
5555
5656
57- test_killVar :: TestAVar _
57+ test_killVar :: TestAVar String
5858 test_killVar = do
5959 v <- makeVar
6060 killVar v (error "DOA ")
6161 e <- attempt $ takeVar v
6262 either (const $ print "Success : Killed queue dead ") (const $ print "Failure : Oh noes , queue survived !") e
6363
64- test_finally :: TestAVar _
64+ test_finally :: TestAVar String
6565 test_finally = do
6666 v <- makeVar
6767 finally
@@ -76,47 +76,47 @@ module Examples where
7676 print $ if n1 + n2 + n3 == 42 then " Success: effects amount to 42."
7777 else " Failure: Expected 42."
7878
79- test_parRace :: TestAVar _
79+ test_parRace :: TestAVar String
8080 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") <|>
8282 Par (later' 200 $ pure "Failure: Late bird got the worm"))
8383 print s
8484
85- test_parRaceKill1 :: TestAVar _
85+ test_parRaceKill1 :: TestAVar String
8686 test_parRaceKill1 = do
87- s <- runPar (Par (later' 100 $ throwError (error ("Oh noes!"))) <|>
87+ s <- runPar (Par (later' 100 $ throwError (error ("Oh noes!"))) <|>
8888 Par (later' 200 $ pure "Success : Early error was ignored in favor of late success "))
8989 print s
9090
91- test_parRaceKill2 :: TestAVar _
91+ test_parRaceKill2 :: TestAVar String
9292 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!"))) <|>
9494 Par (later' 200 $ throwError (error ("Oh noes!"))))
9595 either (const $ print "Success : Killing both kills it dead ") (const $ print "Failure : It's alive !!!") e
9696
97- test_semigroupCanceler :: Test _
98- test_semigroupCanceler =
99- let
97+ test_semigroupCanceler :: Test String
98+ test_semigroupCanceler =
99+ let
100100 c = Canceler (const (pure true)) <> Canceler (const (pure true))
101- in do
101+ in do
102102 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 "
104104 else "Failure : Could not cancel semigroup composite canceler ")
105105
106- test_cancelLater :: TestAVar _
106+ test_cancelLater :: TestAVar String
107107 test_cancelLater = do
108108 c <- forkAff $ (do pure "Binding "
109109 _ <- later' 100 $ print ("Failure: Later was not canceled!")
110110 pure "Binding ")
111111 v <- cancel c (error "Cause ")
112112 print (if v then "Success : Canceled later " else "Failure : Did not cancel later ")
113113
114- test_cancelPar :: TestAVar _
114+ test_cancelPar :: TestAVar String
115115 test_cancelPar = do
116116 c <- forkAff <<< runPar $ Par (later' 100 $ print "Failure : #1 should not get through ") <|>
117117 Par (later' 100 $ print "Failure : #2 should not get through ")
118118 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 "
120120 else "Failure : Canceling composite of two Par failed ")
121121
122122 main = launchAff $ do
0 commit comments