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">
13
<h1>CodeMirror: Haskell mode</h1>
15
<form><textarea id="code" name="code">
21
-- | Find all unique permutations of a list where there might be duplicates.
22
uniquePerms :: (Eq a) => [a] -> [[a]]
23
uniquePerms = permBag . makeBag
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)]
29
makeBag :: (Eq a) => [a] -> Bag a
31
makeBag (a:as) = mix a $ makeBag as
34
mix a (bn@(b,n):bs) | a == b = (b,n+1):bs
35
| otherwise = bn : mix a bs
37
permBag :: Bag a -> [[a]]
39
permBag bs = concatMap (\(f,cs) -> map (f:) $ permBag cs) . oneOfEach $ bs
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)
46
apSnd f (a,b) = (a, f b)
51
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
58
<p><strong>MIME types defined:</strong> <code>text/x-haskell</code>.</p>