-
Notifications
You must be signed in to change notification settings - Fork 0
/
InterpretAlgOpr.hs
64 lines (55 loc) · 2.03 KB
/
InterpretAlgOpr.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{-# LANGUAGE FlexibleContexts #-}
module InterpretAlgOpr where
import InterpretPure
import Interpret
import TransducerAlgOpr
import Transducer
import AlgOpr
import Nondeterministic
import Nat
import Log
import Pointed
import MyShow
import Control.Monad
import Control.Monad.Writer.Class
import Control.Monad.State.Class
import Data.Maybe
import qualified Data.Map as M
oplusGoI str s t = watchBounds str $ oplusGoILog s t
drfGoI str loc = watchBounds str $ drfGoILog loc
asgGoI str loc val t = watchBounds str $ asgGoILog loc val t
-- oplusGoI :: (MonadNondet m, MonadWriter Log m, Pointed x, Pointed y, MyShow x, MyShow y) =>
-- String -> TdGoI m x -> TdGoI m y -> TdGoI m (Maybe (Either x y))
-- oplusGoI str s t = watchBounds str $ oplusTd s t
oplusGoILog :: (MonadNondet m, MonadWriter Log m, Pointed x, Pointed y) =>
TdGoI m x -> TdGoI m y -> TdGoI m (Maybe (Either x y))
oplusGoILog s t = commentAlgOpr "nondeterministic choice" $ oplusTd s t
{-
oplusGoILog s t = Td $ \ a -> do
x0 <- get
when (isNothing x0) $ tell $ Log [LogStr "nondeterministic choice"]
getTd (oplusTd s t) a
-}
drfGoILog :: (MonadState (M.Map l Nat) m, MonadWriter Log m, Ord l, MyShow l) =>
l -> TdGoI m (Maybe (Nat, ()))
drfGoILog loc = commentAlgOpr ("lookup(" ++ myShow loc ++ ")") $
lookupTd loc (\ n -> constGoILog n)
{-
drfGoILog loc = Td $ \ a -> do
x0 <- get
when (isNothing x0) $ tell $ Log [LogStr $ "lookup_" ++ show loc]
getTd (lookupTd loc (\ n -> constGoILog n)) a
-}
asgGoILog :: (MonadWriter Log m, MonadState (M.Map l v) m, Pointed x,
Ord l, MyShow l, Show v) =>
l -> v -> TdGoI m x -> TdGoI m (Maybe ((), x))
asgGoILog loc val t =
commentAlgOpr ("update(" ++ myShow loc ++ "," ++ show val ++")") $
updateTd loc val (\ _ -> t)
-- say something at the first call of the algebraic operation
commentAlgOpr :: (MonadWriter Log m) =>
String -> TdGoI m (Maybe x) -> TdGoI m (Maybe x)
commentAlgOpr str t = Td $ \ a -> do
x0 <- get
when (isNothing x0) $ tell $ Log [LogStrLn $ "*** algebraic operation *** : " ++ str]
getTd t a