-
Here is a code example, starting with definition of effects used: data FileSystemE :: Effect where
FileExists :: FilePath -> FileSystemE m Bool
ReadFile :: FilePath -> FileSystemE m (Stream m Word8)
fileExists :: FileSystemE :> es => FilePath -> Eff es Bool
fileExists = Eff.send . FileExists
readFile :: FileSystemE :> es => FilePath -> Eff es (Stream (Eff es) Word8)
readFile = Eff.send . ReadFile Secondly here is a usage example. As you can see it's a bit messy: newtype DoesNotExistError = DoesNotExistError FilePath deriving Show
-- | First check if file exists, then read byte stream from the file.
readFileCheck
:: (Error DoesNotExistError :> es1, FileSystemE :> es1, FileSystemE :> es2)
=> FilePath
-> Eff es1 (Eff es2 (Stream (Eff es2) Word8))
readFileCheck path = fileExists path >>= \case
False -> throwError $ FileNotExistsError path
True -> pure $ readFile path |
Beta Was this translation helpful? Give feedback.
Answered by
jerbaroo
Jul 29, 2025
Replies: 1 comment 1 reply
-
You can try to modify the constructor like that:
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The following ensures an effect
FileSystemE
supports reading a stream of bytes from a file, with an additionalError
effect inside the stream.