mirror of
https://github.com/iritmaximus/haskell.git
synced 2026-10-12 19:13:39 +03:00
Move Set 11b Ex 5 to Set 13b
This commit is contained in:
@@ -82,34 +82,6 @@ doubleCall op = todo
|
||||
compose :: (a -> IO b) -> (c -> IO a) -> c -> IO b
|
||||
compose op1 op2 c = todo
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- Ex 5: Implement the operation mkCounter that produces the IO operations
|
||||
-- inc :: IO () and get :: IO Int. These operations should work like this:
|
||||
--
|
||||
-- get returns the number of times inc has been called
|
||||
--
|
||||
-- In other words, a simple stateful counter. Use an IORef to store the count.
|
||||
--
|
||||
-- Note: this is an IO operation that produces two IO operations. Thus
|
||||
-- the type of mkCounter is IO (IO (), IO Int).
|
||||
--
|
||||
-- This exercise is tricky. Feel free to leave it until later.
|
||||
--
|
||||
-- An example of how mkCounter works in GHCi:
|
||||
--
|
||||
-- *Set11b> (inc,get) <- mkCounter
|
||||
-- *Set11b> inc
|
||||
-- *Set11b> inc
|
||||
-- *Set11b> get
|
||||
-- 2
|
||||
-- *Set11b> inc
|
||||
-- *Set11b> inc
|
||||
-- *Set11b> get
|
||||
-- 4
|
||||
|
||||
mkCounter :: IO (IO (), IO Int)
|
||||
mkCounter = todo
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- Ex 6: Reading lines from a file. The module System.IO defines
|
||||
-- operations for Handles, which represent open files that can be read
|
||||
|
||||
Reference in New Issue
Block a user