Skip to content

Commit

Permalink
Introduced a general class WebPageRendering as a sub-class of Experim…
Browse files Browse the repository at this point in the history
…entRendering.
  • Loading branch information
dsorokin committed Oct 4, 2014
1 parent 0a75b3b commit 8611678
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Simulation/Aivika/Experiment/ExperimentSpecsView.hs
Expand Up @@ -43,7 +43,7 @@ defaultExperimentSpecsView =
experimentSpecsDescription = "It shows the experiment specs.",
experimentSpecsWriter = defaultExperimentSpecsWriter }

instance ExperimentView ExperimentSpecsView WebPageRenderer WebPageWriter where
instance WebPageRendering r => ExperimentView ExperimentSpecsView r WebPageWriter where

outputView v =
let reporter exp renderer dir =
Expand Down
2 changes: 1 addition & 1 deletion Simulation/Aivika/Experiment/FinalStatsView.hs
Expand Up @@ -58,7 +58,7 @@ defaultFinalStatsView =
finalStatsTransform = id,
finalStatsSeries = id }

instance ExperimentView FinalStatsView WebPageRenderer WebPageWriter where
instance WebPageRendering r => ExperimentView FinalStatsView r WebPageWriter where

outputView v =
let reporter exp renderer dir =
Expand Down
2 changes: 1 addition & 1 deletion Simulation/Aivika/Experiment/FinalTableView.hs
Expand Up @@ -94,7 +94,7 @@ defaultFinalTableView =
finalTableTransform = expandResults,
finalTableSeries = id }

instance ExperimentView FinalTableView WebPageRenderer WebPageWriter where
instance WebPageRendering r => ExperimentView FinalTableView r WebPageWriter where

outputView v =
let reporter exp renderer dir =
Expand Down
2 changes: 1 addition & 1 deletion Simulation/Aivika/Experiment/LastValueView.hs
Expand Up @@ -64,7 +64,7 @@ defaultLastValueView =
lastValueTransform = id,
lastValueSeries = id }

instance ExperimentView LastValueView WebPageRenderer WebPageWriter where
instance WebPageRendering r => ExperimentView LastValueView r WebPageWriter where

outputView v =
let reporter exp renderer dir =
Expand Down
2 changes: 1 addition & 1 deletion Simulation/Aivika/Experiment/TableView.hs
Expand Up @@ -112,7 +112,7 @@ defaultTableView =
tableTransform = expandResults,
tableSeries = id }

instance ExperimentView TableView WebPageRenderer WebPageWriter where
instance WebPageRendering r => ExperimentView TableView r WebPageWriter where

outputView v =
let reporter exp renderer dir =
Expand Down
2 changes: 1 addition & 1 deletion Simulation/Aivika/Experiment/TimingStatsView.hs
Expand Up @@ -69,7 +69,7 @@ defaultTimingStatsView =
timingStatsTransform = id,
timingStatsSeries = id }

instance ExperimentView TimingStatsView WebPageRenderer WebPageWriter where
instance WebPageRendering r => ExperimentView TimingStatsView r WebPageWriter where

outputView v =
let reporter exp renderer dir =
Expand Down
23 changes: 15 additions & 8 deletions Simulation/Aivika/Experiment/Types.hs
@@ -1,5 +1,5 @@

{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, RankNTypes #-}
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, RankNTypes, FlexibleContexts #-}

-- |
-- Module : Simulation.Aivika.Experiment.Types
Expand All @@ -22,7 +22,7 @@
module Simulation.Aivika.Experiment.Types
(-- * General Definitions
Experiment(..),
ExperimentRenderer(..),
ExperimentRendering(..),
defaultExperiment,
runExperiment,
runExperimentParallel,
Expand All @@ -35,6 +35,7 @@ module Simulation.Aivika.Experiment.Types
expandFilePath,
mapFilePath,
-- * Web Page Rendering
WebPageRendering(..),
WebPageRenderer(..),
WebPageWriter(..)) where

Expand Down Expand Up @@ -95,7 +96,7 @@ defaultExperiment =
experimentNumCapabilities = getNumCapabilities }

-- | It allows rendering the simulation results in an arbitrary way.
class ExperimentRenderer r a | r -> a where
class ExperimentRendering r a | r -> a where

-- | Render the experiment after the simulation is finished, for example,
-- creating the @index.html@ file in the specified directory.
Expand All @@ -110,7 +111,7 @@ data ExperimentGenerator r a =
-- | Defines a view in which the simulation results should be saved.
-- You should extend this type class to define your own views such
-- as the PDF document.
class ExperimentRenderer r a => ExperimentView v r a | r -> a where
class ExperimentRendering r a => ExperimentView v r a | r -> a where

-- | Create a generator of the reporter.
outputView :: v -> ExperimentGenerator r a
Expand Down Expand Up @@ -143,7 +144,7 @@ data ExperimentReporter r a =
-- | Run the simulation experiment sequentially. For example,
-- it can be a Monte-Carlo simulation dependentent on the external
-- 'Parameter' values.
runExperiment :: ExperimentRenderer r a
runExperiment :: ExperimentRendering r a
=> Experiment r a
-- ^ the simulation experiment to run
-> r
Expand All @@ -165,7 +166,7 @@ runExperiment = runExperimentWithExecutor sequence_
-- threads directly with help of 'experimentNumCapabilities',
-- although the real number of parallel threads can depend on many
-- factors.
runExperimentParallel :: ExperimentRenderer r a
runExperimentParallel :: ExperimentRendering r a
=> Experiment r a
-- ^ the simulation experiment to run
-> r
Expand All @@ -180,7 +181,7 @@ runExperimentParallel e = runExperimentWithExecutor executor e
parallel_ pool tasks

-- | Run the simulation experiment with the specified executor.
runExperimentWithExecutor :: ExperimentRenderer r a
runExperimentWithExecutor :: ExperimentRendering r a
=> ([IO ()] -> IO ())
-- ^ an executor that allows parallelizing the simulation if required
-> Experiment r a
Expand Down Expand Up @@ -240,7 +241,13 @@ data WebPageWriter =
-- the ordered number of the item.
}

instance ExperimentRenderer WebPageRenderer WebPageWriter where
-- | A subclass of renderers that know how to save the @index.html@ file
-- when rendering the simulation experiment.
class ExperimentRendering r WebPageWriter => WebPageRendering r

instance WebPageRendering WebPageRenderer

instance ExperimentRendering WebPageRenderer WebPageWriter where

renderExperiment e r reporters path =
do let html :: HtmlWriter ()
Expand Down
1 change: 1 addition & 0 deletions aivika-experiment.cabal
Expand Up @@ -53,6 +53,7 @@ library
aivika >= 1.4

extensions: FlexibleInstances,
FlexibleContexts,
MultiParamTypeClasses,
FunctionalDependencies,
RankNTypes
Expand Down

0 comments on commit 8611678

Please sign in to comment.