From 0175a7347f9f462ccf0f7ff294a2cbd00b108a49 Mon Sep 17 00:00:00 2001 From: Andy Li <1450947+andy1li@users.noreply.github.com> Date: Tue, 5 Nov 2024 08:28:47 +0800 Subject: [PATCH] Disable buffering for Haskell --- compiled_starters/haskell/app/Main.hs | 6 +++++- solutions/haskell/01-jm1/code/app/Main.hs | 6 +++++- solutions/haskell/01-jm1/diff/app/Main.hs.diff | 8 ++++++-- starter_templates/haskell/code/app/Main.hs | 6 +++++- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/compiled_starters/haskell/app/Main.hs b/compiled_starters/haskell/app/Main.hs index 9462192f..14e97be4 100644 --- a/compiled_starters/haskell/app/Main.hs +++ b/compiled_starters/haskell/app/Main.hs @@ -5,10 +5,14 @@ module Main (main) where import Network.Simple.TCP (serve, HostPreference(HostAny), closeSock) - +import System.IO (hSetBuffering, stdout, stderr, BufferMode(NoBuffering)) main :: IO () main = do + -- Disable output buffering + hSetBuffering stdout NoBuffering + hSetBuffering stderr NoBuffering + -- You can use print statements as follows for debugging, they'll be visible when running tests. putStrLn "Logs from your program will appear here" diff --git a/solutions/haskell/01-jm1/code/app/Main.hs b/solutions/haskell/01-jm1/code/app/Main.hs index 28db1e17..a8f7b76d 100644 --- a/solutions/haskell/01-jm1/code/app/Main.hs +++ b/solutions/haskell/01-jm1/code/app/Main.hs @@ -5,10 +5,14 @@ module Main (main) where import Network.Simple.TCP (serve, HostPreference(HostAny), closeSock) - +import System.IO (hSetBuffering, stdout, stderr, BufferMode(NoBuffering)) main :: IO () main = do + -- Disable output buffering + hSetBuffering stdout NoBuffering + hSetBuffering stderr NoBuffering + let port = "6379" putStrLn $ "Redis server listening on port " ++ port serve HostAny port $ \(socket, address) -> do diff --git a/solutions/haskell/01-jm1/diff/app/Main.hs.diff b/solutions/haskell/01-jm1/diff/app/Main.hs.diff index 1f1d4e52..02358587 100644 --- a/solutions/haskell/01-jm1/diff/app/Main.hs.diff +++ b/solutions/haskell/01-jm1/diff/app/Main.hs.diff @@ -1,4 +1,4 @@ -@@ -1,20 +1,16 @@ +@@ -1,24 +1,20 @@ {-# OPTIONS_GHC -Wno-unused-top-binds #-} {-# LANGUAGE BlockArguments #-} {-# LANGUAGE OverloadedStrings #-} @@ -6,10 +6,14 @@ module Main (main) where import Network.Simple.TCP (serve, HostPreference(HostAny), closeSock) - + import System.IO (hSetBuffering, stdout, stderr, BufferMode(NoBuffering)) main :: IO () main = do + -- Disable output buffering + hSetBuffering stdout NoBuffering + hSetBuffering stderr NoBuffering + - -- You can use print statements as follows for debugging, they'll be visible when running tests. - putStrLn "Logs from your program will appear here" - diff --git a/starter_templates/haskell/code/app/Main.hs b/starter_templates/haskell/code/app/Main.hs index 9462192f..14e97be4 100644 --- a/starter_templates/haskell/code/app/Main.hs +++ b/starter_templates/haskell/code/app/Main.hs @@ -5,10 +5,14 @@ module Main (main) where import Network.Simple.TCP (serve, HostPreference(HostAny), closeSock) - +import System.IO (hSetBuffering, stdout, stderr, BufferMode(NoBuffering)) main :: IO () main = do + -- Disable output buffering + hSetBuffering stdout NoBuffering + hSetBuffering stderr NoBuffering + -- You can use print statements as follows for debugging, they'll be visible when running tests. putStrLn "Logs from your program will appear here"