I have a function that looks like this:
outputDelayCo :: Maybe Int -> (Event -> ByteString) -> [Event] -> Int -> IO ()
outputDelayCo Nothing = outputDelay Nothing
outputDelayCo (Just 1) = do exitSuccess
outputDelayCo (Just n) = outputDelay (Just (n-1))
I get this error:
Couldn't match expected type ‘(Event -> ByteString)
-> [Event] -> Int -> IO ()’
with actual type ‘IO a0’
In a stmt of a 'do' block: exitSuccess
In the expression: do { exitSuccess }
I can fix this by doing this, but it is much uglier:
outputDelayCo :: Maybe Int -> (Event -> ByteString) -> [Event] -> Int -> IO ()
outputDelayCo Nothing a b c = outputDelay Nothing a b c
outputDelayCo (Just 1) _ _ _ = do exitSuccess
outputDelayCo (Just n) a b c = outputDelay (Just (n-1)) a b c
I understand why the error occurs: exitSuccess will have an IO I / O type, so the types do not match this pattern. But what is the right / elegant way to do this?
source
share