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