-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.hs
53 lines (33 loc) · 1.38 KB
/
Main.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
import Control.Monad.State
import Data.Set (Set, empty)
data Node a = Node a
deriving Show
data Graph a = Graph (Set (Node a)) (Set (Int, Int)) (Maybe Int)
deriving Show
newtype StringN = StringN String
deriving Show
class EquivClass a where
generate :: a -> [a]
class Splittable a where
split :: Node a -> Maybe (Node a, Node a)
class Combinable a where
combine :: Node a -> Node a -> Node a
class SetTransform a where
transformSets :: (Set a, Set a) -> State Int (Set a, Set a)
class SeqTransform a where
transformSeq :: EquivClass a => [a] -> State Int [a]
gen n s = foldl (\s accum -> [ x++y | x<-accum, y<-s]) s $ replicate (n-1) s
instance EquivClass StringN where
generate (StringN s) = map StringN $ gen (length s) [ [x] | x <- ['A'..'Z']]
instance SeqTransform StringN where
transformSeq seqs = mapM generateNext seqs
where generateNext s = do
cur <- get
put (cur+1)
return $ (generate s) !! cur
toSeq :: Graph a -> [a]
toSeq graph@(Graph nodes edges (Just rootIndex)) = depthFirst graph rootIndex
toSeq graph = depthFirst graph 0
depthFirst :: Graph a -> Int -> [a]
depthFirst graph rootIndex = depthFirst' graph rootIndex empty []
depthFirst' graph@(Graph nodes edges _) rootIndex visited accum = undefined