mirror of
https://github.com/iritmaximus/haskell.git
synced 2026-10-12 19:13:39 +03:00
Set 11b: fix exercise numbering
This commit is contained in:
+3
-3
@@ -83,7 +83,7 @@ compose :: (a -> IO b) -> (c -> IO a) -> c -> IO b
|
|||||||
compose op1 op2 c = todo
|
compose op1 op2 c = todo
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
-- Ex 6: Reading lines from a file. The module System.IO defines
|
-- Ex 5: Reading lines from a file. The module System.IO defines
|
||||||
-- operations for Handles, which represent open files that can be read
|
-- operations for Handles, which represent open files that can be read
|
||||||
-- from or written to. Here are some functions that might be useful:
|
-- from or written to. Here are some functions that might be useful:
|
||||||
--
|
--
|
||||||
@@ -113,7 +113,7 @@ hFetchLines :: Handle -> IO [String]
|
|||||||
hFetchLines = todo
|
hFetchLines = todo
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
-- Ex 7: Given a Handle and a list of line indexes, produce the lines
|
-- Ex 6: Given a Handle and a list of line indexes, produce the lines
|
||||||
-- at those indexes from the file.
|
-- at those indexes from the file.
|
||||||
--
|
--
|
||||||
-- Line indexing starts from 1.
|
-- Line indexing starts from 1.
|
||||||
@@ -126,7 +126,7 @@ hSelectLines :: Handle -> [Int] -> IO [String]
|
|||||||
hSelectLines h nums = todo
|
hSelectLines h nums = todo
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
-- Ex 8: In this exercise we see how a program can be split into a
|
-- Ex 7: In this exercise we see how a program can be split into a
|
||||||
-- pure part that does all of the work, and a simple IO wrapper that
|
-- pure part that does all of the work, and a simple IO wrapper that
|
||||||
-- drives the pure logic.
|
-- drives the pure logic.
|
||||||
--
|
--
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ tests = [(1,"appendAll",[ex1])
|
|||||||
,(2,"swapIORefs",[ex2])
|
,(2,"swapIORefs",[ex2])
|
||||||
,(3,"doubleCall",[ex3_doubleCall, ex3_doubleCall_2])
|
,(3,"doubleCall",[ex3_doubleCall, ex3_doubleCall_2])
|
||||||
,(4,"composeIO",[ex4_composeIO_1, ex4_composeIO_2])
|
,(4,"composeIO",[ex4_composeIO_1, ex4_composeIO_2])
|
||||||
,(6,"hFetchLines",[ex6])
|
,(5,"hFetchLines",[ex5])
|
||||||
,(7,"hSelectLines",[ex7_hSelectLines])
|
,(6,"hSelectLines",[ex6_hSelectLines])
|
||||||
,(8,"interact'",[ex8_interact_terminates, ex8_interact_example, ex8_interact_loop])]
|
,(7,"interact'",[ex7_interact_terminates, ex7_interact_example, ex7_interact_loop])]
|
||||||
|
|
||||||
-- -- -- -- --
|
-- -- -- -- --
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ ex4_composeIO_2 =
|
|||||||
($ compose (return . (*2)) (return . (+1)) i) . withNoInput $
|
($ compose (return . (*2)) (return . (+1)) i) . withNoInput $
|
||||||
checkResult (?== (i+1)*2)
|
checkResult (?== (i+1)*2)
|
||||||
|
|
||||||
ex6 = forAllBlind (listOf1 word) $ \lines ->
|
ex5 = forAllBlind (listOf1 word) $ \lines ->
|
||||||
counterexample ("Contents of handle h:\n"++unlines lines) $
|
counterexample ("Contents of handle h:\n"++unlines lines) $
|
||||||
counterexample "hFetchLines h" $
|
counterexample "hFetchLines h" $
|
||||||
monadicIO $ do
|
monadicIO $ do
|
||||||
@@ -92,7 +92,7 @@ ex6 = forAllBlind (listOf1 word) $ \lines ->
|
|||||||
run $ hClose h
|
run $ hClose h
|
||||||
stop_ $ outs ?== lines
|
stop_ $ outs ?== lines
|
||||||
|
|
||||||
ex7_hSelectLines =
|
ex6_hSelectLines =
|
||||||
forAllBlind (listOf1 word) $ \lines ->
|
forAllBlind (listOf1 word) $ \lines ->
|
||||||
forAllBlind (fmap (nub.sort) . listOf1 $ choose (1,length lines)) $ \inds ->
|
forAllBlind (fmap (nub.sort) . listOf1 $ choose (1,length lines)) $ \inds ->
|
||||||
counterexample ("Contents of handle h:\n"++unlines lines) $
|
counterexample ("Contents of handle h:\n"++unlines lines) $
|
||||||
@@ -115,7 +115,7 @@ counter ("inc",n) = (True,"done",n+1)
|
|||||||
counter ("print",n) = (True,show n,n)
|
counter ("print",n) = (True,show n,n)
|
||||||
counter ("quit",n) = (False,"bye bye",n)
|
counter ("quit",n) = (False,"bye bye",n)
|
||||||
|
|
||||||
ex8_interact_terminates =
|
ex7_interact_terminates =
|
||||||
forAllBlind word $ \w1 ->
|
forAllBlind word $ \w1 ->
|
||||||
forAllBlind word $ \w2 ->
|
forAllBlind word $ \w2 ->
|
||||||
forAllBlind (choose (0::Int,100)) $ \state ->
|
forAllBlind (choose (0::Int,100)) $ \state ->
|
||||||
@@ -123,11 +123,11 @@ ex8_interact_terminates =
|
|||||||
($ let f (input,state) = (False,input,state) in interact' f state) . withInput (unlines [w1,w2]) $
|
($ let f (input,state) = (False,input,state) in interact' f state) . withInput (unlines [w1,w2]) $
|
||||||
check (?==(w1++"\n")) (?==state)
|
check (?==(w1++"\n")) (?==state)
|
||||||
|
|
||||||
ex8_interact_example =
|
ex7_interact_example =
|
||||||
$(testing' [|interact' counter 1|]) . withInput (unlines ["print","inc","inc","print","quit"]) $
|
$(testing' [|interact' counter 1|]) . withInput (unlines ["print","inc","inc","print","quit"]) $
|
||||||
check (?==unlines ["1","done","done","3","bye bye"]) (?==3)
|
check (?==unlines ["1","done","done","3","bye bye"]) (?==3)
|
||||||
|
|
||||||
ex8_interact_loop =
|
ex7_interact_loop =
|
||||||
forAllBlind (choose (0::Int,100)) $ \state ->
|
forAllBlind (choose (0::Int,100)) $ \state ->
|
||||||
forAllBlind (choose (0::Int,5)) $ \steps ->
|
forAllBlind (choose (0::Int,5)) $ \steps ->
|
||||||
forAllBlind word $ \w ->
|
forAllBlind word $ \w ->
|
||||||
|
|||||||
Reference in New Issue
Block a user