mirror of
https://github.com/IHaskell/IHaskell.git
synced 2025-04-19 12:56:08 +00:00
Remove all uses of fromJust
This commit is contained in:
parent
726999ae1e
commit
64d54a7afc
@ -35,11 +35,11 @@ fromJustConvertSpec convertSpec = convertSpec
|
||||
, convertLhsStyle = Identity $ fromMaybe (LT.pack <$> lhsStyleBird) (convertLhsStyle convertSpec)
|
||||
}
|
||||
where
|
||||
toIpynb = fromMaybe (error "Error: direction for conversion unknown")
|
||||
toIpynb = fromMaybe (error "fromJustConvertSpec: direction for conversion unknown")
|
||||
(convertToIpynb convertSpec)
|
||||
(inputFile, outputFile) =
|
||||
case (convertInput convertSpec, convertOutput convertSpec) of
|
||||
(Nothing, Nothing) -> error "Error: no files specified for conversion"
|
||||
(Nothing, Nothing) -> error "fromJustConvertSpec: no files specified for conversion"
|
||||
(Just i, Nothing)
|
||||
| toIpynb -> (i, dropExtension i <.> "ipynb")
|
||||
| otherwise -> (i, dropExtension i <.> "lhs")
|
||||
|
@ -36,7 +36,7 @@ import System.IO (hGetChar, hSetEncoding, utf8)
|
||||
import System.Random (getStdGen, randomRs)
|
||||
import System.Process
|
||||
import System.Exit
|
||||
import Data.Maybe (fromJust)
|
||||
import Data.Maybe (mapMaybe)
|
||||
import System.Environment (getEnv)
|
||||
|
||||
import qualified GHC.Paths
|
||||
@ -532,7 +532,7 @@ evalCommand _output (Directive SetDynFlag flagsStr) state = safely state $ do
|
||||
}
|
||||
else do
|
||||
-- Apply all IHaskell flag updaters to the state to get the new state
|
||||
let state' = foldl' (.) id (map (fromJust . ihaskellFlagUpdater) ihaskellFlags) state
|
||||
let state' = foldl' (.) id (mapMaybe ihaskellFlagUpdater ihaskellFlags) state
|
||||
errs <- setFlags ghcFlags
|
||||
let disp =
|
||||
case errs of
|
||||
@ -689,21 +689,18 @@ evalCommand publish (Directive ShellCmd cmd) state = wrapExecution state $
|
||||
modifyMVar_ outputAccum (return . (++ nextChunk))
|
||||
|
||||
-- Check if we're done.
|
||||
exitCode <- getProcessExitCode process
|
||||
let computationDone = isJust exitCode
|
||||
|
||||
when computationDone $ do
|
||||
next <- readChars pipe "" maxSize
|
||||
modifyMVar_ outputAccum (return . (++ next))
|
||||
|
||||
if not computationDone
|
||||
then do
|
||||
mExitCode <- getProcessExitCode process
|
||||
case mExitCode of
|
||||
Nothing -> do
|
||||
-- Process still running
|
||||
next <- readChars pipe "" maxSize
|
||||
modifyMVar_ outputAccum (return . (++ next))
|
||||
-- Write to frontend and repeat.
|
||||
readMVar outputAccum >>= output
|
||||
loop
|
||||
else do
|
||||
Just exitCode -> do
|
||||
out <- readMVar outputAccum
|
||||
case fromJust exitCode of
|
||||
case exitCode of
|
||||
ExitSuccess -> return $ Display [plain out]
|
||||
ExitFailure code -> do
|
||||
let errMsg = "Process exited with error code " ++ show code
|
||||
|
@ -248,11 +248,8 @@ extractPackageName lnk = do
|
||||
return $ pieces List.!! (latestLoc - 1)
|
||||
|
||||
extractModuleName :: String -> Maybe String
|
||||
extractModuleName lnk = do
|
||||
let pieces = split "/" lnk
|
||||
guard $ not $ null pieces
|
||||
let html = fromJust $ lastMay pieces
|
||||
return $ replace "-" "." $ takeWhile (/= '.') html
|
||||
extractModuleName lnk =
|
||||
replace "-" "." . takeWhile (/= '.') <$> lastMay (split "/" lnk)
|
||||
|
||||
div' :: String -> String -> String
|
||||
div' = printf "<div class='%s'>%s</div>"
|
||||
|
@ -196,9 +196,8 @@ subHome path = SH.shelly $ do
|
||||
parseVersion :: String -> Maybe [Int]
|
||||
parseVersion versionStr =
|
||||
let versions = map readMay $ split "." versionStr
|
||||
parsed = all isJust versions
|
||||
in if parsed
|
||||
then Just $ map fromJust versions
|
||||
in if all isJust versions
|
||||
then Just $ catMaybes versions
|
||||
else Nothing
|
||||
|
||||
-- | Get the absolute path to this IHaskell executable.
|
||||
|
@ -31,6 +31,7 @@ import Control.Concurrent
|
||||
import Control.Applicative ((<$>))
|
||||
import GHC.IO.Handle
|
||||
import GHC.IO.Handle.Types
|
||||
import System.FilePath ((</>))
|
||||
import System.Posix.IO
|
||||
import System.IO.Unsafe
|
||||
|
||||
@ -47,7 +48,9 @@ stdinInterface = unsafePerformIO newEmptyMVar
|
||||
fixStdin :: String -> IO ()
|
||||
fixStdin dir = do
|
||||
-- Initialize the stdin interface.
|
||||
profile <- fromJust . readMay <$> readFile (dir ++ "/.kernel-profile")
|
||||
let fpath = dir </> ".kernel-profile"
|
||||
profile <- fromMaybe (error $ "fixStdin: Failed reading " ++ fpath)
|
||||
. readMay <$> readFile fpath
|
||||
interface <- serveStdin profile
|
||||
putMVar stdinInterface interface
|
||||
void $ forkIO $ stdinOnce dir
|
||||
@ -86,7 +89,9 @@ getInputLine dir = do
|
||||
|
||||
-- Send a request for input.
|
||||
uuid <- UUID.random
|
||||
parentHdr <- fromJust . readMay <$> readFile (dir ++ "/.last-req-header")
|
||||
let fpath = dir </> ".last-req-header"
|
||||
parentHdr <- fromMaybe (error $ "getInputLine: Failed reading " ++ fpath)
|
||||
. readMay <$> readFile fpath
|
||||
let hdr = MessageHeader (mhIdentifiers parentHdr) (Just parentHdr) mempty
|
||||
uuid (mhSessionId parentHdr) (mhUsername parentHdr) InputRequestMessage
|
||||
let msg = RequestInput hdr ""
|
||||
|
Loading…
x
Reference in New Issue
Block a user