-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tests.hs
137 lines (85 loc) · 3.31 KB
/
Tests.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
{-# LANGUAGE GADTs
, FlexibleInstances
, TypeFamilies
, FlexibleContexts
, DeriveFunctor
#-}
module Test where
import Control.Applicative
import Control.Arrow
import Data.Monoid
import Data.Function(on)
--import Control.Category
--import Prelude hiding ((.),id) -- we use those from Category...
import StateMachine
import Internal.MachineComponent
import Data.Char
{-
TODO...
-}
{-
To check laws:
As Applicative:
identity
pure id <*> v = v
composition
pure (.) <*> u <*> v <*> w = u <*> (v <*> w)
homomorphism
pure f <*> pure x = pure (f x)
interchange
u <*> pure y = pure ($ y) <*> u
As Alternative:
zero element left:
empty <|> x = x
zero element right:
x <|> empty = x
associativeness:
x <|> ( y <|> z) = ( x <|> y ) <|> z
As category:
identity:
f.id == id.f == f
associativity:
(h.f).g = h.(f.g)
As Arrow:
arr id = id
arr (f >>> g) = arr f >>> arr g
first (arr f) = arr (first f)
first (f >>> g) = first f >>> first g
first f >>> arr fst = arr fst >>> f
first f >>> arr (id *** g) = arr (id *** g) >>> first f
first (first f) >>> arr assoc = arr assoc >>> first f
where
assoc ((a,b),c) = (a,(b,c))
As ArrowChoice:
left (arr f) = arr (left f)
left (f >>> g) = left f >>> left g
f >>> arr Left = arr Left >>> left f
left f >>> arr (id +++ g) = arr (id +++ g) >>> left f
left (left f) >>> arr assocsum = arr assocsum >>> left f
where
assocsum (Left (Left x)) = Left x
assocsum (Left (Right y)) = Right (Left y)
assocsum (Right z) = Right (Right z)
-}
debuging::StateMachine Char String -> String -> String
debuging (Wrap parse) [] = unlines
[ unlines $ debug parse
, "#################################"
, "####### Partially got: " ++ show (collect parse)
, "<---------------------------------------> End of the stream: <--------------------------------->"
, "#################################################################################################"
, ""
, ""
]
debuging (Wrap parse) (c:cs) = unlines
[ unlines $ debug parse
, "#################################"
, "####### Partially got: " ++ show (collect parse)
, "#################################################################################################"
, "Feeding with: "++ show c
, ""
, case (trigger c parse) of
(Nothing) -> "<--------------- Suddenly end of parseser :( XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX>"
(Just parse') -> debuging (Wrap parse') cs
]
--p = Sequenced (Step True Nothing (const (Just "o")) ) (Left (Left (Step True Nothing (const $Just ('h':)) )))