diff options
author | Pushkar Joshi | 2012-02-24 12:08:49 -0800 |
---|---|---|
committer | Pushkar Joshi | 2012-02-24 12:08:49 -0800 |
commit | 03ca7a5ed13c25faaa9100bb666e062fd15335e6 (patch) | |
tree | c51112223ceb9121cd595a60335eb2795215590f /imports/codemirror/mode/haskell/index.html | |
parent | fcb12cc09eb3cd3b42bd215877ba18f449275b75 (diff) | |
parent | 053fc63a2950c7a5ee4ebf98033b64d474a3c46e (diff) | |
download | ninja-03ca7a5ed13c25faaa9100bb666e062fd15335e6.tar.gz |
Merge branch 'pentool' into brushtool
Conflicts:
imports/codemirror/mode/scheme/scheme.js
js/tools/BrushTool.js
Diffstat (limited to 'imports/codemirror/mode/haskell/index.html')
-rwxr-xr-x | imports/codemirror/mode/haskell/index.html | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/imports/codemirror/mode/haskell/index.html b/imports/codemirror/mode/haskell/index.html new file mode 100755 index 00000000..15706e71 --- /dev/null +++ b/imports/codemirror/mode/haskell/index.html | |||
@@ -0,0 +1,60 @@ | |||
1 | <!doctype html> | ||
2 | <html> | ||
3 | <head> | ||
4 | <title>CodeMirror: Haskell mode</title> | ||
5 | <link rel="stylesheet" href="../../lib/codemirror.css"> | ||
6 | <script src="../../lib/codemirror.js"></script> | ||
7 | <script src="haskell.js"></script> | ||
8 | <link rel="stylesheet" href="../../theme/elegant.css"> | ||
9 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | ||
10 | <link rel="stylesheet" href="../../doc/docs.css"> | ||
11 | </head> | ||
12 | <body> | ||
13 | <h1>CodeMirror: Haskell mode</h1> | ||
14 | |||
15 | <form><textarea id="code" name="code"> | ||
16 | module UniquePerms ( | ||
17 | uniquePerms | ||
18 | ) | ||
19 | where | ||
20 | |||
21 | -- | Find all unique permutations of a list where there might be duplicates. | ||
22 | uniquePerms :: (Eq a) => [a] -> [[a]] | ||
23 | uniquePerms = permBag . makeBag | ||
24 | |||
25 | -- | An unordered collection where duplicate values are allowed, | ||
26 | -- but represented with a single value and a count. | ||
27 | type Bag a = [(a, Int)] | ||
28 | |||
29 | makeBag :: (Eq a) => [a] -> Bag a | ||
30 | makeBag [] = [] | ||
31 | makeBag (a:as) = mix a $ makeBag as | ||
32 | where | ||
33 | mix a [] = [(a,1)] | ||
34 | mix a (bn@(b,n):bs) | a == b = (b,n+1):bs | ||
35 | | otherwise = bn : mix a bs | ||
36 | |||
37 | permBag :: Bag a -> [[a]] | ||
38 | permBag [] = [[]] | ||
39 | permBag bs = concatMap (\(f,cs) -> map (f:) $ permBag cs) . oneOfEach $ bs | ||
40 | where | ||
41 | oneOfEach [] = [] | ||
42 | oneOfEach (an@(a,n):bs) = | ||
43 | let bs' = if n == 1 then bs else (a,n-1):bs | ||
44 | in (a,bs') : mapSnd (an:) (oneOfEach bs) | ||
45 | |||
46 | apSnd f (a,b) = (a, f b) | ||
47 | mapSnd = map . apSnd | ||
48 | </textarea></form> | ||
49 | |||
50 | <script> | ||
51 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | ||
52 | lineNumbers: true, | ||
53 | matchBrackets: true, | ||
54 | theme: "elegant" | ||
55 | }); | ||
56 | </script> | ||
57 | |||
58 | <p><strong>MIME types defined:</strong> <code>text/x-haskell</code>.</p> | ||
59 | </body> | ||
60 | </html> | ||