-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExperiments.hs
More file actions
40 lines (25 loc) · 830 Bytes
/
Experiments.hs
File metadata and controls
40 lines (25 loc) · 830 Bytes
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
30
31
32
33
34
35
36
37
38
39
40
module Experiments where
import InterBasics(join)
import Control.Monad(replicateM)
import System.IO(hSetBuffering,stdout,BufferMode(LineBuffering))
{- getting n lines - still consumes the whole of the input :-( -}
getNlines :: Int -> IO String
getNlines 0 =
return []
getNlines n =
do l <- getLine
ls <- getNlines (n-1)
return (l++ls)
{- using getNlines in an interaction -}
interactN :: Int -> (String -> String) -> IO ()
interactN n f =
do input <- replicateM n getLine
putStr (f (join input))
{- setting buffering before doing an interaction -}
interactL :: (String -> String) -> IO ()
interactL f =
do hSetBuffering stdout LineBuffering
interact f
{- "bare" interactions -}
necho :: String -> String
necho ~(x:xs) = "Prompt: " ++ [x] ++ "\n" ++ necho xs