-
Notifications
You must be signed in to change notification settings - Fork 1
/
Generator.hs
51 lines (47 loc) · 1.46 KB
/
Generator.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
module Main where
import Data.List.Class (ListItem(..),fromList,toList,genericTake)
import Control.Monad.ListT
import Control.Monad.Generator
import Control.Monad.Trans
hanoi :: Monad m => Int -> Char -> Char -> Char -> GeneratorT (Char,Char) m ()
hanoi 0 _ _ _ = return ()
hanoi n from to other = do
hanoi (n-1) from other to
yield (from, to)
hanoi (n-1) other to from
{--
generate $ hanoi 3 'a' 'b' 'c'
[[('a','b'),('a','c'),('b','c'),('a','b'),('c','a'),('c','b'),('a','b')]]
h 3 a b c
h 2 a c b
h 1 a b c
h 0 a c b
(a,b)
h 0 b c a
(a,c)
h 1 b c a
h 0 b a c
(b,c)
h 0 a c b
--}
bits prev= do
yield prev
x <- lift "01"
bits (prev ++ [x])
{--
genericTake 2 $ generate bits ""
ListT {runListT =
[Cons {headL = "",
tailL = ListT {runListT =
[Cons {headL = "0",
tailL = ListT {runListT =
[Cons {headL = "00",
tailL = ListT {runListT = [Nil]}},
Cons {headL = "01",
tailL = ListT {runListT = [Nil]}}]}},
Cons {headL = "1",
tailL = ListT {runListT =
[Cons {headL = "10",
tailL = ListT {runListT = [Nil]}},
Cons {headL = "11", tailL = ListT {runListT = [Nil]}}]}}]}}]}
--}