Commit 4ebe3434 authored by Adam Vogt's avatar Adam Vogt

add monoid instance for Kernel to avoid some duplication.

data-default may be prettier instead, since there isn't a canonical
mappend.
parent a40d6bfb
......@@ -7,6 +7,7 @@ import Data.List
import System.Directory
import Data.String.Here
import Data.String.Utils (strip, replace)
import Data.Monoid
import IHaskell.Eval.Parser
import IHaskell.Types
......@@ -33,7 +34,7 @@ eval string = do
outputAccum <- newIORef []
let publish _ displayDatas = modifyIORef outputAccum (displayDatas :)
getTemporaryDirectory >>= setCurrentDirectory
let state = KernelState 1 LintOff
let state = mempty :: KernelState
interpret $ Eval.evaluate state string publish
out <- readIORef outputAccum
return $ reverse out
......
......@@ -75,6 +75,13 @@ data KernelState = KernelState
getCwd :: String
}
-- | like 'First', except also add up the execution counter
instance Monoid KernelState where
mempty = KernelState 1 LintOn "."
KernelState na sa cwda `mappend` KernelState nb sb cwdb =
KernelState (na+nb) sa cwda
-- | Initialization information for the kernel.
data InitInfo = InitInfo {
extensions :: [String], -- ^ Extensions to enable at start.
......
......@@ -260,11 +260,7 @@ runKernel profileSrc initInfo = do
-- Initial kernel state.
initialKernelState :: IO (MVar KernelState)
initialKernelState =
newMVar KernelState {
getExecutionCounter = 1,
getLintStatus = LintOn,
getCwd = "."
}
newMVar mempty
-- | Duplicate a message header, giving it a new UUID and message type.
dupHeader :: MessageHeader -> MessageType -> IO MessageHeader
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment