index.html 2.1 KB

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