move a few things away in to-be-integrated/
[myslice.git] / to-be-integrated / third-party / codemirror-3.15 / mode / haskell / index.html
1 <!doctype html>
2 <html>
3   <head>
4     <meta charset="utf-8">
5     <title>CodeMirror: Haskell mode</title>
6     <link rel="stylesheet" href="../../lib/codemirror.css">
7     <script src="../../lib/codemirror.js"></script>
8     <script src="../../addon/edit/matchbrackets.js"></script>
9     <script src="haskell.js"></script>
10     <link rel="stylesheet" href="../../theme/elegant.css">
11     <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
12     <link rel="stylesheet" href="../../doc/docs.css">
13   </head>
14   <body>
15     <h1>CodeMirror: Haskell mode</h1>
16
17 <form><textarea id="code" name="code">
18 module UniquePerms (
19     uniquePerms
20     )
21 where
22
23 -- | Find all unique permutations of a list where there might be duplicates.
24 uniquePerms :: (Eq a) => [a] -> [[a]]
25 uniquePerms = permBag . makeBag
26
27 -- | An unordered collection where duplicate values are allowed,
28 -- but represented with a single value and a count.
29 type Bag a = [(a, Int)]
30
31 makeBag :: (Eq a) => [a] -> Bag a
32 makeBag [] = []
33 makeBag (a:as) = mix a $ makeBag as
34   where
35     mix a []                        = [(a,1)]
36     mix a (bn@(b,n):bs) | a == b    = (b,n+1):bs
37                         | otherwise = bn : mix a bs
38
39 permBag :: Bag a -> [[a]]
40 permBag [] = [[]]
41 permBag bs = concatMap (\(f,cs) -> map (f:) $ permBag cs) . oneOfEach $ bs
42   where
43     oneOfEach [] = []
44     oneOfEach (an@(a,n):bs) =
45         let bs' = if n == 1 then bs else (a,n-1):bs
46         in (a,bs') : mapSnd (an:) (oneOfEach bs)
47     
48     apSnd f (a,b) = (a, f b)
49     mapSnd = map . apSnd
50 </textarea></form>
51
52     <script>
53       var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
54         lineNumbers: true,
55         matchBrackets: true,
56         theme: "elegant"
57       });
58     </script>
59
60     <p><strong>MIME types defined:</strong> <code>text/x-haskell</code>.</p>
61   </body>
62 </html>