Skip to content

Commit b66287a

Browse files
authored
Merge pull request #106 from codecrafters-io/disable-buffering-for-haskell
CC-1491: Disable stderr/out buffering for Haskell starter code
2 parents d0f7bab + 6587e32 commit b66287a

File tree

7 files changed

+87
-67
lines changed

7 files changed

+87
-67
lines changed

compiled_starters/haskell/app/Main.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Main where
22

33
import System.Environment
44
import System.Exit
5+
import System.IO (hSetBuffering, stdout, stderr, BufferMode (NoBuffering))
56

67
matchPattern :: String -> String -> Bool
78
matchPattern pattern input = do
@@ -11,6 +12,10 @@ matchPattern pattern input = do
1112

1213
main :: IO ()
1314
main = do
15+
-- Disable output buffering
16+
hSetBuffering stdout NoBuffering
17+
hSetBuffering stderr NoBuffering
18+
1419
args <- getArgs
1520
let pattern = args !! 1
1621
input_line <- getLine

compiled_starters/haskell/package.yaml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,36 @@
66
#
77
# DON'T EDIT THIS!
88

9-
name: hs-grep-clone
10-
version: 0.1.0.0
11-
license: BSD3
9+
name: hs-grep-clone
10+
version: 0.1.0.0
11+
license: BSD3
1212

1313
dependencies:
14-
- base >= 4.7 && < 5
15-
- megaparsec # can help when implementing the parser
16-
- parser-combinators # extends megaparsec
17-
- containers # Set, Map, Seq
18-
- unordered-containers # HashSet, HashMap
19-
- hashable # when using your own data types with unordered-containers
20-
- mtl # monad transformers to help with nested monads
14+
- base >= 4.7 && < 5
15+
- megaparsec # can help when implementing the parser
16+
- parser-combinators # extends megaparsec
17+
- containers # Set, Map, Seq
18+
- unordered-containers # HashSet, HashMap
19+
- hashable # when using your own data types with unordered-containers
20+
- mtl # monad transformers to help with nested monads
2121

2222
default-extensions:
23-
- BlockArguments
24-
- ImportQualifiedPost
25-
- LambdaCase
26-
- NamedFieldPuns
27-
- RecordWildCards
23+
- BlockArguments
24+
- ImportQualifiedPost
25+
- LambdaCase
26+
- NamedFieldPuns
27+
- RecordWildCards
2828

2929
library:
30-
source-dirs: src
30+
source-dirs: app
3131

3232
executables:
3333
hs-grep-clone-exe:
34-
main: Main.hs
35-
source-dirs: app
34+
main: Main.hs
35+
source-dirs: app
3636
ghc-options:
37-
- -threaded
38-
- -rtsopts
39-
- -with-rtsopts=-N
37+
- -threaded
38+
- -rtsopts
39+
- -with-rtsopts=-N
4040
dependencies:
41-
- hs-grep-clone
41+
- hs-grep-clone

solutions/haskell/01-cq2/code/app/Main.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Main where
22

33
import System.Environment
44
import System.Exit
5+
import System.IO (hSetBuffering, stdout, stderr, BufferMode (NoBuffering))
56

67
matchPattern :: String -> String -> Bool
78
matchPattern pattern input = do
@@ -11,6 +12,10 @@ matchPattern pattern input = do
1112

1213
main :: IO ()
1314
main = do
15+
-- Disable output buffering
16+
hSetBuffering stdout NoBuffering
17+
hSetBuffering stderr NoBuffering
18+
1419
args <- getArgs
1520
let pattern = args !! 1
1621
input_line <- getLine

solutions/haskell/01-cq2/code/package.yaml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,36 @@
66
#
77
# DON'T EDIT THIS!
88

9-
name: hs-grep-clone
10-
version: 0.1.0.0
11-
license: BSD3
9+
name: hs-grep-clone
10+
version: 0.1.0.0
11+
license: BSD3
1212

1313
dependencies:
14-
- base >= 4.7 && < 5
15-
- megaparsec # can help when implementing the parser
16-
- parser-combinators # extends megaparsec
17-
- containers # Set, Map, Seq
18-
- unordered-containers # HashSet, HashMap
19-
- hashable # when using your own data types with unordered-containers
20-
- mtl # monad transformers to help with nested monads
14+
- base >= 4.7 && < 5
15+
- megaparsec # can help when implementing the parser
16+
- parser-combinators # extends megaparsec
17+
- containers # Set, Map, Seq
18+
- unordered-containers # HashSet, HashMap
19+
- hashable # when using your own data types with unordered-containers
20+
- mtl # monad transformers to help with nested monads
2121

2222
default-extensions:
23-
- BlockArguments
24-
- ImportQualifiedPost
25-
- LambdaCase
26-
- NamedFieldPuns
27-
- RecordWildCards
23+
- BlockArguments
24+
- ImportQualifiedPost
25+
- LambdaCase
26+
- NamedFieldPuns
27+
- RecordWildCards
2828

2929
library:
30-
source-dirs: src
30+
source-dirs: app
3131

3232
executables:
3333
hs-grep-clone-exe:
34-
main: Main.hs
35-
source-dirs: app
34+
main: Main.hs
35+
source-dirs: app
3636
ghc-options:
37-
- -threaded
38-
- -rtsopts
39-
- -with-rtsopts=-N
37+
- -threaded
38+
- -rtsopts
39+
- -with-rtsopts=-N
4040
dependencies:
41-
- hs-grep-clone
41+
- hs-grep-clone

solutions/haskell/01-cq2/diff/app/Main.hs.diff

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
@@ -1,28 +1,24 @@
1+
@@ -1,33 +1,29 @@
22
module Main where
33

44
import System.Environment
55
import System.Exit
6+
import System.IO (hSetBuffering, stdout, stderr, BufferMode (NoBuffering))
67

78
matchPattern :: String -> String -> Bool
89
matchPattern pattern input = do
@@ -12,6 +13,10 @@
1213

1314
main :: IO ()
1415
main = do
16+
-- Disable output buffering
17+
hSetBuffering stdout NoBuffering
18+
hSetBuffering stderr NoBuffering
19+
1520
args <- getArgs
1621
let pattern = args !! 1
1722
input_line <- getLine

starter_templates/haskell/code/app/Main.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Main where
22

33
import System.Environment
44
import System.Exit
5+
import System.IO (hSetBuffering, stdout, stderr, BufferMode (NoBuffering))
56

67
matchPattern :: String -> String -> Bool
78
matchPattern pattern input = do
@@ -11,6 +12,10 @@ matchPattern pattern input = do
1112

1213
main :: IO ()
1314
main = do
15+
-- Disable output buffering
16+
hSetBuffering stdout NoBuffering
17+
hSetBuffering stderr NoBuffering
18+
1419
args <- getArgs
1520
let pattern = args !! 1
1621
input_line <- getLine

starter_templates/haskell/code/package.yaml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,36 @@
66
#
77
# DON'T EDIT THIS!
88

9-
name: hs-grep-clone
10-
version: 0.1.0.0
11-
license: BSD3
9+
name: hs-grep-clone
10+
version: 0.1.0.0
11+
license: BSD3
1212

1313
dependencies:
14-
- base >= 4.7 && < 5
15-
- megaparsec # can help when implementing the parser
16-
- parser-combinators # extends megaparsec
17-
- containers # Set, Map, Seq
18-
- unordered-containers # HashSet, HashMap
19-
- hashable # when using your own data types with unordered-containers
20-
- mtl # monad transformers to help with nested monads
14+
- base >= 4.7 && < 5
15+
- megaparsec # can help when implementing the parser
16+
- parser-combinators # extends megaparsec
17+
- containers # Set, Map, Seq
18+
- unordered-containers # HashSet, HashMap
19+
- hashable # when using your own data types with unordered-containers
20+
- mtl # monad transformers to help with nested monads
2121

2222
default-extensions:
23-
- BlockArguments
24-
- ImportQualifiedPost
25-
- LambdaCase
26-
- NamedFieldPuns
27-
- RecordWildCards
23+
- BlockArguments
24+
- ImportQualifiedPost
25+
- LambdaCase
26+
- NamedFieldPuns
27+
- RecordWildCards
2828

2929
library:
30-
source-dirs: src
30+
source-dirs: app
3131

3232
executables:
3333
hs-grep-clone-exe:
34-
main: Main.hs
35-
source-dirs: app
34+
main: Main.hs
35+
source-dirs: app
3636
ghc-options:
37-
- -threaded
38-
- -rtsopts
39-
- -with-rtsopts=-N
37+
- -threaded
38+
- -rtsopts
39+
- -with-rtsopts=-N
4040
dependencies:
41-
- hs-grep-clone
41+
- hs-grep-clone

0 commit comments

Comments
 (0)