import qualified Bar as Bar
import qualified Foo as Foo
import Cont
data Stack s = Empty | s ::: Stack s ; infixr 5 :::
data States = FooState Foo.FooState | BarState Bar.BarState
run :: Stack States -> Stack States
run Empty = error "Empty stack"
run (s ::: rest) = proceed (run' s) rest
run' :: States -> Cont
run' (FooState s) = Foo.run s
run' (BarState s) = Bar.run s
proceed :: Cont -> Stack States -> Stack States
proceed (Cont s) rest = undefined ::: rest
proceed (Start s s') rest = undefined ::: undefined ::: rest
proceed (End s) rest = rest
main = print $ Foo.run Foo.FInit
module Foo (FooState(..), run) where
import qualified Bar as Bar
import Cont
data FooState = FInit | FBar | FEnd deriving Show
run FInit = Start FBar Bar.BInit
run FBar = End FEnd
module Bar (BarState(..), run) where
import Cont
data BarState = BInit | BMid | BEnd deriving Show
run BInit = Cont BMid
run BMid = End BEnd
{-# LANGUAGE GADTs, StandaloneDeriving #-}
module Cont (Cont(..)) where
-- Cont type describes how to continue
data Cont where
Cont :: Show s => s -> Cont
Start :: (Show s, Show s') => s -> s' -> Cont
End :: Show s => s -> Cont
deriving instance Show Cont
{
"version": "0.1.0.0",
"cells": [
"let \n cnode :: Colour Double -> String -> QDiagram SVG V2 Double Any; cnode c n = text n # fontSizeL 0.2 # fc white <> circle 0.27 # scaleX 1.2 # fc c # named n \n fcnode :: Colour Double -> String -> QDiagram SVG V2 Double Any; fcnode c n = (circle 0.30 # scaleX 1.2 <> cnode c n)\n end :: QDiagram SVG V2 Double Any -> QDiagram SVG V2 Double Any; end n = circle 0.30 # scaleX 1.2 <> n\n bnode = cnode green\n fnode = cnode blue\n \n connect :: QDiagram SVG V2 Double Any -> (String, String) -> QDiagram SVG V2 Double Any; connect d (a, b) = d # connectOutside a b\n connectAll :: [(String, String)] -> QDiagram SVG V2 Double Any -> QDiagram SVG V2 Double Any; connectAll list d = mconcat $ map (connect d) list\n bMachine = connectAll [(\"BInit\", \"BMid\"), (\"BMid\", \"BEnd\")] (atPoints (map p2 [(0, 1), (0, 0), (0, -1)]) [bnode \"BInit\", bnode \"BMid\", end $ bnode \"BEnd\"])\n bFlow = (text \"BarFlow\" # fontSizeL 0.15 # fc black # rotateBy (0.25) ) ||| strutX 0.2 ||| (circle 1.5 # scaleX 0.5 # named \"BFlow\" <> bMachine) \n fMachine = connectAll [(\"FInit\", \"BFlow\"), (\"BFlow\", \"FEnd\")] $ atPoints (map p2 [(0, 1), (0, -1), (0, -3)]) [fnode \"FInit\", bFlow, end $ fnode \"FEnd\"]\nin\n\ndia $ frame 0.1 $ (circle 3 # translate (r2 (1.2, -1)) # scaleX 0.5 <> fMachine) # translate (r2 (0, 1)) ||| strutX 0.2 ||| (text \"FooFlow\" # fontSizeL 0.15 # fc black # rotateBy (0.25) )"
],
"importModules": "Hyper.Extra\nDiagrams.Prelude\nData.Typeable\nDiagrams.Backend.SVG",
"loadFiles": "",
"settings": {
"packageTool": "stack",
"packagePath": "../haskell/stack.yaml",
"searchPath": "../worksheets"
}
}