diff options
author | Christiaan Baaij <christiaan.baaij@gmail.com> | 2017-06-09 08:26:43 +0200 |
---|---|---|
committer | Alex Biehl <alexbiehl@gmail.com> | 2017-06-09 08:26:43 +0200 |
commit | 87c551fc668b9251f2647cce8772f205e1cee154 (patch) | |
tree | 1ccf05ad324e83a77b21997f2442e890d7d6feb6 /html-test | |
parent | d912ee70fff0718440a6f281ccea73aaf8568685 (diff) |
Haddock support for bundled pattern synonyms (#627)
* Haddock support for bundled pattern synonyms
* Add fixities to bundled pattern synonyms
* Add bundled pattern synonyms to the synopsis
* Store bundled pattern fixities in expItemFixities
* Add test for bundled pattern synonyms
* Stop threading fixities
* Include bundled pattern synonyms for re-exported data types
Sadly, fixity information isn't found for re-exported data types
* Support for pattern synonyms
* Modify tests after #631
* Test some reexport variations
* Also lookup bundled pattern synonyms from `InstalledInterface`s
* Check isExported for bundled pattern synonyms
* Pattern synonym is exported check
* Always look for pattern synonyms in the current module
Another overlooked cornercase
* Account for types named twice in export lists
Also introduce a fast function for nubbing on a `Name` and use it
throughout the code base.
* correct fixities for reexported pattern synonyms
* Fuse concatMap and map
* Remove obsolete import
* Add pattern synonyms to visible exports
* Fix test
* Remove corner case
Diffstat (limited to 'html-test')
-rw-r--r-- | html-test/ref/BundledPatterns.html | 474 | ||||
-rw-r--r-- | html-test/ref/BundledPatterns2.html | 472 | ||||
-rw-r--r-- | html-test/src/BundledPatterns.hs | 110 | ||||
-rw-r--r-- | html-test/src/BundledPatterns2.hs | 10 |
4 files changed, 1066 insertions, 0 deletions
diff --git a/html-test/ref/BundledPatterns.html b/html-test/ref/BundledPatterns.html new file mode 100644 index 00000000..bf6c073c --- /dev/null +++ b/html-test/ref/BundledPatterns.html @@ -0,0 +1,474 @@ +<html xmlns="http://www.w3.org/1999/xhtml" +><head + ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" + /><title + >BundledPatterns</title + ><link href="#" rel="stylesheet" type="text/css" title="Ocean" + /><script src="haddock-util.js" type="text/javascript" + ></script + ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript" + ></script + ><script type="text/javascript" + >// +window.onload = function () {pageLoad();}; +// +</script + ></head + ><body + ><div id="package-header" + ><ul class="links" id="page-menu" + ><li + ><a href="#" + >Contents</a + ></li + ><li + ><a href="#" + >Index</a + ></li + ></ul + ><p class="caption empty" + ></p + ></div + ><div id="content" + ><div id="module-header" + ><table class="info" + ><tr + ><th + >Safe Haskell</th + ><td + >None</td + ></tr + ></table + ><p class="caption" + >BundledPatterns</p + ></div + ><div id="synopsis" + ><p id="control.syn" class="caption expander" onclick="toggleSection('syn')" + >Synopsis</p + ><ul id="section.syn" class="hide" onclick="toggleSection('syn')" + ><li class="src short" + ><span class="keyword" + >data</span + > <a href="#" + >Vec</a + > :: <a href="#" + >Nat</a + > -> <a href="#" + >*</a + > -> <a href="#" + >*</a + > <span class="keyword" + >where</span + ><ul class="subs" + ><li + ><a href="#" + >Nil</a + > :: <a href="#" + >Vec</a + > 0 a</li + ><li + ><span class="keyword" + >pattern</span + > <a href="#" + >(:>)</a + > :: a -> <a href="#" + >Vec</a + > n a -> <a href="#" + >Vec</a + > (n <a href="#" + >+</a + > 1) a</li + ></ul + ></li + ><li class="src short" + ><span class="keyword" + >data</span + > <a href="#" + >RTree</a + > :: <a href="#" + >Nat</a + > -> <a href="#" + >*</a + > -> <a href="#" + >*</a + > <span class="keyword" + >where</span + ><ul class="subs" + ><li + ><span class="keyword" + >pattern</span + > <a href="#" + >LR</a + > :: a -> <a href="#" + >RTree</a + > 0 a</li + ><li + ><span class="keyword" + >pattern</span + > <a href="#" + >BR</a + > :: <a href="#" + >RTree</a + > d a -> <a href="#" + >RTree</a + > d a -> <a href="#" + >RTree</a + > (d <a href="#" + >+</a + > 1) a</li + ></ul + ></li + ></ul + ></div + ><div id="interface" + ><h1 + >Documentation</h1 + ><div class="top" + ><p class="src" + ><span class="keyword" + >data</span + > <a id="t:Vec" class="def" + >Vec</a + > :: <a href="#" + >Nat</a + > -> <a href="#" + >*</a + > -> <a href="#" + >*</a + > <span class="keyword" + >where</span + > <a href="#" class="selflink" + >#</a + ></p + ><div class="doc" + ><p + >Fixed size vectors.</p + ><ul + ><li + >Lists with their length encoded in their type</li + ><li + ><code + ><a href="#" + >Vec</a + ></code + >tor elements have an <strong + >ASCENDING</strong + > subscript starting from 0 and + ending at <code + ><code + ><a href="#" + >length</a + ></code + > - 1</code + >.</li + ></ul + ></div + ><div class="subs constructors" + ><p class="caption" + >Constructors</p + ><table + ><tr + ><td class="src" + ><a id="v:Nil" class="def" + >Nil</a + > :: <a href="#" + >Vec</a + > 0 a</td + ><td class="doc empty" + ></td + ></tr + ></table + ></div + ><div class="subs bundled-patterns" + ><p class="caption" + >Bundled Patterns</p + ><table + ><tr + ><td class="src" + ><span class="keyword" + >pattern</span + > <a id="v::-62-" class="def" + >(:>)</a + > :: a -> <a href="#" + >Vec</a + > n a -> <a href="#" + >Vec</a + > (n <a href="#" + >+</a + > 1) a <span class="fixity" + >infixr 5</span + ><span class="rightedge" + ></span + ></td + ><td class="doc" + ><p + >Add an element to the head of a vector.</p + ><pre class="screen" + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >3:>4:>5:>Nil +</code + ></strong + ><3,4,5> +<code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >let x = 3:>4:>5:>Nil +</code + ></strong + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >:t x +</code + ></strong + >x :: Num a => Vec 3 a +</pre + ><p + >Can be used as a pattern:</p + ><pre class="screen" + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >let f (x :> y :> _) = x + y +</code + ></strong + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >:t f +</code + ></strong + >f :: Num a => Vec ((n + 1) + 1) a -> a +<code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >f (3:>4:>5:>6:>7:>Nil) +</code + ></strong + >7 +</pre + ><p + >Also in conjunctions with (<code + >:<</code + >):</p + ><pre class="screen" + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >let g (a :> b :> (_ :< y :< x)) = a + b + x + y +</code + ></strong + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >:t g +</code + ></strong + >g :: Num a => Vec ((((n + 1) + 1) + 1) + 1) a -> a +<code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >g (1:>2:>3:>4:>5:>Nil) +</code + ></strong + >12 +</pre + ></td + ></tr + ></table + ></div + ></div + ><div class="top" + ><p class="src" + ><span class="keyword" + >data</span + > <a id="t:RTree" class="def" + >RTree</a + > :: <a href="#" + >Nat</a + > -> <a href="#" + >*</a + > -> <a href="#" + >*</a + > <span class="keyword" + >where</span + > <a href="#" class="selflink" + >#</a + ></p + ><div class="doc" + ><p + >Perfect depth binary tree.</p + ><ul + ><li + >Only has elements at the leaf of the tree</li + ><li + >A tree of depth <em + >d</em + > has <em + >2^d</em + > elements.</li + ></ul + ></div + ><div class="subs bundled-patterns" + ><p class="caption" + >Bundled Patterns</p + ><table + ><tr + ><td class="src" + ><span class="keyword" + >pattern</span + > <a id="v:LR" class="def" + >LR</a + > :: a -> <a href="#" + >RTree</a + > 0 a</td + ><td class="doc" + ><p + >Leaf of a perfect depth tree</p + ><pre class="screen" + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >LR 1 +</code + ></strong + >1 +<code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >let x = LR 1 +</code + ></strong + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >:t x +</code + ></strong + >x :: Num a => RTree 0 a +</pre + ><p + >Can be used as a pattern:</p + ><pre class="screen" + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >let f (LR a) (LR b) = a + b +</code + ></strong + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >:t f +</code + ></strong + >f :: Num a => RTree 0 a -> RTree 0 a -> a +<code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >f (LR 1) (LR 2) +</code + ></strong + >3 +</pre + ></td + ></tr + ><tr + ><td class="src" + ><span class="keyword" + >pattern</span + > <a id="v:BR" class="def" + >BR</a + > :: <a href="#" + >RTree</a + > d a -> <a href="#" + >RTree</a + > d a -> <a href="#" + >RTree</a + > (d <a href="#" + >+</a + > 1) a</td + ><td class="doc" + ><p + >Branch of a perfect depth tree</p + ><pre class="screen" + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >BR (LR 1) (LR 2) +</code + ></strong + ><1,2> +<code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >let x = BR (LR 1) (LR 2) +</code + ></strong + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >:t x +</code + ></strong + >x :: Num a => RTree 1 a +</pre + ><p + >Case be used a pattern:</p + ><pre class="screen" + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >let f (BR (LR a) (LR b)) = LR (a + b) +</code + ></strong + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >:t f +</code + ></strong + >f :: Num a => RTree 1 a -> RTree 0 a +<code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >f (BR (LR 1) (LR 2)) +</code + ></strong + >3 +</pre + ></td + ></tr + ></table + ></div + ></div + ></div + ></div + ><div id="footer" + ></div + ></body + ></html +>
\ No newline at end of file diff --git a/html-test/ref/BundledPatterns2.html b/html-test/ref/BundledPatterns2.html new file mode 100644 index 00000000..3d1d4da0 --- /dev/null +++ b/html-test/ref/BundledPatterns2.html @@ -0,0 +1,472 @@ +<html xmlns="http://www.w3.org/1999/xhtml" +><head + ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" + /><title + >BundledPatterns2</title + ><link href="#" rel="stylesheet" type="text/css" title="Ocean" + /><script src="haddock-util.js" type="text/javascript" + ></script + ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript" + ></script + ><script type="text/javascript" + >// +window.onload = function () {pageLoad();}; +// +</script + ></head + ><body + ><div id="package-header" + ><ul class="links" id="page-menu" + ><li + ><a href="#" + >Contents</a + ></li + ><li + ><a href="#" + >Index</a + ></li + ></ul + ><p class="caption empty" + ></p + ></div + ><div id="content" + ><div id="module-header" + ><table class="info" + ><tr + ><th + >Safe Haskell</th + ><td + >None</td + ></tr + ></table + ><p class="caption" + >BundledPatterns2</p + ></div + ><div id="synopsis" + ><p id="control.syn" class="caption expander" onclick="toggleSection('syn')" + >Synopsis</p + ><ul id="section.syn" class="hide" onclick="toggleSection('syn')" + ><li class="src short" + ><span class="keyword" + >data</span + > <a href="#" + >Vec</a + > :: <a href="#" + >Nat</a + > -> <a href="#" + >*</a + > -> <a href="#" + >*</a + > <span class="keyword" + >where</span + ><ul class="subs" + ><li + ><span class="keyword" + >pattern</span + > <a href="#" + >Empty</a + > :: <a href="#" + >Vec</a + > 0 a</li + ><li + ><span class="keyword" + >pattern</span + > <a href="#" + >(:>)</a + > :: a -> <a href="#" + >Vec</a + > n a -> <a href="#" + >Vec</a + > (n <a href="#" + >+</a + > 1) a</li + ></ul + ></li + ><li class="src short" + ><span class="keyword" + >data</span + > <a href="#" + >RTree</a + > :: <a href="#" + >Nat</a + > -> <a href="#" + >*</a + > -> <a href="#" + >*</a + > <span class="keyword" + >where</span + ><ul class="subs" + ><li + ><span class="keyword" + >pattern</span + > <a href="#" + >LR</a + > :: a -> <a href="#" + >RTree</a + > 0 a</li + ><li + ><span class="keyword" + >pattern</span + > <a href="#" + >BR</a + > :: <a href="#" + >RTree</a + > d a -> <a href="#" + >RTree</a + > d a -> <a href="#" + >RTree</a + > (d <a href="#" + >+</a + > 1) a</li + ></ul + ></li + ></ul + ></div + ><div id="interface" + ><h1 + >Documentation</h1 + ><div class="top" + ><p class="src" + ><span class="keyword" + >data</span + > <a id="t:Vec" class="def" + >Vec</a + > :: <a href="#" + >Nat</a + > -> <a href="#" + >*</a + > -> <a href="#" + >*</a + > <span class="keyword" + >where</span + > <a href="#" class="selflink" + >#</a + ></p + ><div class="doc" + ><p + >Fixed size vectors.</p + ><ul + ><li + >Lists with their length encoded in their type</li + ><li + ><code + ><a href="#" + >Vec</a + ></code + >tor elements have an <strong + >ASCENDING</strong + > subscript starting from 0 and + ending at <code + ><code + ><a href="#" + >length</a + ></code + > - 1</code + >.</li + ></ul + ></div + ><div class="subs bundled-patterns" + ><p class="caption" + >Bundled Patterns</p + ><table + ><tr + ><td class="src" + ><span class="keyword" + >pattern</span + > <a id="v:Empty" class="def" + >Empty</a + > :: <a href="#" + >Vec</a + > 0 a</td + ><td class="doc empty" + ></td + ></tr + ><tr + ><td class="src" + ><span class="keyword" + >pattern</span + > <a id="v::-62-" class="def" + >(:>)</a + > :: a -> <a href="#" + >Vec</a + > n a -> <a href="#" + >Vec</a + > (n <a href="#" + >+</a + > 1) a <span class="fixity" + >infixr 5</span + ><span class="rightedge" + ></span + ></td + ><td class="doc" + ><p + >Add an element to the head of a vector.</p + ><pre class="screen" + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >3:>4:>5:>Nil +</code + ></strong + ><3,4,5> +<code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >let x = 3:>4:>5:>Nil +</code + ></strong + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >:t x +</code + ></strong + >x :: Num a => Vec 3 a +</pre + ><p + >Can be used as a pattern:</p + ><pre class="screen" + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >let f (x :> y :> _) = x + y +</code + ></strong + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >:t f +</code + ></strong + >f :: Num a => Vec ((n + 1) + 1) a -> a +<code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >f (3:>4:>5:>6:>7:>Nil) +</code + ></strong + >7 +</pre + ><p + >Also in conjunctions with (<code + >:<</code + >):</p + ><pre class="screen" + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >let g (a :> b :> (_ :< y :< x)) = a + b + x + y +</code + ></strong + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >:t g +</code + ></strong + >g :: Num a => Vec ((((n + 1) + 1) + 1) + 1) a -> a +<code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >g (1:>2:>3:>4:>5:>Nil) +</code + ></strong + >12 +</pre + ></td + ></tr + ></table + ></div + ></div + ><div class="top" + ><p class="src" + ><span class="keyword" + >data</span + > <a id="t:RTree" class="def" + >RTree</a + > :: <a href="#" + >Nat</a + > -> <a href="#" + >*</a + > -> <a href="#" + >*</a + > <span class="keyword" + >where</span + > <a href="#" class="selflink" + >#</a + ></p + ><div class="doc" + ><p + >Perfect depth binary tree.</p + ><ul + ><li + >Only has elements at the leaf of the tree</li + ><li + >A tree of depth <em + >d</em + > has <em + >2^d</em + > elements.</li + ></ul + ></div + ><div class="subs bundled-patterns" + ><p class="caption" + >Bundled Patterns</p + ><table + ><tr + ><td class="src" + ><span class="keyword" + >pattern</span + > <a id="v:LR" class="def" + >LR</a + > :: a -> <a href="#" + >RTree</a + > 0 a</td + ><td class="doc" + ><p + >Leaf of a perfect depth tree</p + ><pre class="screen" + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >LR 1 +</code + ></strong + >1 +<code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >let x = LR 1 +</code + ></strong + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >:t x +</code + ></strong + >x :: Num a => RTree 0 a +</pre + ><p + >Can be used as a pattern:</p + ><pre class="screen" + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >let f (LR a) (LR b) = a + b +</code + ></strong + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >:t f +</code + ></strong + >f :: Num a => RTree 0 a -> RTree 0 a -> a +<code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >f (LR 1) (LR 2) +</code + ></strong + >3 +</pre + ></td + ></tr + ><tr + ><td class="src" + ><span class="keyword" + >pattern</span + > <a id="v:BR" class="def" + >BR</a + > :: <a href="#" + >RTree</a + > d a -> <a href="#" + >RTree</a + > d a -> <a href="#" + >RTree</a + > (d <a href="#" + >+</a + > 1) a</td + ><td class="doc" + ><p + >Branch of a perfect depth tree</p + ><pre class="screen" + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >BR (LR 1) (LR 2) +</code + ></strong + ><1,2> +<code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >let x = BR (LR 1) (LR 2) +</code + ></strong + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >:t x +</code + ></strong + >x :: Num a => RTree 1 a +</pre + ><p + >Case be used a pattern:</p + ><pre class="screen" + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >let f (BR (LR a) (LR b)) = LR (a + b) +</code + ></strong + ><code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >:t f +</code + ></strong + >f :: Num a => RTree 1 a -> RTree 0 a +<code class="prompt" + >>>> </code + ><strong class="userinput" + ><code + >f (BR (LR 1) (LR 2)) +</code + ></strong + >3 +</pre + ></td + ></tr + ></table + ></div + ></div + ></div + ></div + ><div id="footer" + ></div + ></body + ></html +>
\ No newline at end of file diff --git a/html-test/src/BundledPatterns.hs b/html-test/src/BundledPatterns.hs new file mode 100644 index 00000000..443e64fa --- /dev/null +++ b/html-test/src/BundledPatterns.hs @@ -0,0 +1,110 @@ +{-# LANGUAGE DataKinds, GADTs, KindSignatures, PatternSynonyms, TypeOperators, + ViewPatterns #-} +module BundledPatterns (Vec(Nil,(:>)), RTree (LR,BR)) where + +import GHC.TypeLits +import Prelude hiding (head, tail) +import Unsafe.Coerce + +-- | Fixed size vectors. +-- +-- * Lists with their length encoded in their type +-- * 'Vec'tor elements have an __ASCENDING__ subscript starting from 0 and +-- ending at @'length' - 1@. +data Vec :: Nat -> * -> * where + Nil :: Vec 0 a + Cons :: a -> Vec n a -> Vec (n + 1) a + +infixr 5 `Cons` + +-- | Add an element to the head of a vector. +-- +-- >>> 3:>4:>5:>Nil +-- <3,4,5> +-- >>> let x = 3:>4:>5:>Nil +-- >>> :t x +-- x :: Num a => Vec 3 a +-- +-- Can be used as a pattern: +-- +-- >>> let f (x :> y :> _) = x + y +-- >>> :t f +-- f :: Num a => Vec ((n + 1) + 1) a -> a +-- >>> f (3:>4:>5:>6:>7:>Nil) +-- 7 +-- +-- Also in conjunctions with (':<'): +-- +-- >>> let g (a :> b :> (_ :< y :< x)) = a + b + x + y +-- >>> :t g +-- g :: Num a => Vec ((((n + 1) + 1) + 1) + 1) a -> a +-- >>> g (1:>2:>3:>4:>5:>Nil) +-- 12 +pattern (:>) :: a -> Vec n a -> Vec (n + 1) a +pattern (:>) x xs <- ((\ys -> (head ys,tail ys)) -> (x,xs)) + where + (:>) x xs = Cons x xs + +infixr 5 :> + +head :: Vec (n + 1) a -> a +head (x `Cons` _) = x + +tail :: Vec (n + 1) a -> Vec n a +tail (_ `Cons` xs) = unsafeCoerce xs + +-- | Perfect depth binary tree. +-- +-- * Only has elements at the leaf of the tree +-- * A tree of depth /d/ has /2^d/ elements. +data RTree :: Nat -> * -> * where + LR_ :: a -> RTree 0 a + BR_ :: RTree d a -> RTree d a -> RTree (d+1) a + +textract :: RTree 0 a -> a +textract (LR_ x) = x +{-# NOINLINE textract #-} + +tsplit :: RTree (d+1) a -> (RTree d a,RTree d a) +tsplit (BR_ l r) = (unsafeCoerce l, unsafeCoerce r) +{-# NOINLINE tsplit #-} + +-- | Leaf of a perfect depth tree +-- +-- >>> LR 1 +-- 1 +-- >>> let x = LR 1 +-- >>> :t x +-- x :: Num a => RTree 0 a +-- +-- Can be used as a pattern: +-- +-- >>> let f (LR a) (LR b) = a + b +-- >>> :t f +-- f :: Num a => RTree 0 a -> RTree 0 a -> a +-- >>> f (LR 1) (LR 2) +-- 3 +pattern LR :: a -> RTree 0 a +pattern LR x <- (textract -> x) + where + LR x = LR_ x + +-- | Branch of a perfect depth tree +-- +-- >>> BR (LR 1) (LR 2) +-- <1,2> +-- >>> let x = BR (LR 1) (LR 2) +-- >>> :t x +-- x :: Num a => RTree 1 a +-- +-- Case be used a pattern: +-- +-- >>> let f (BR (LR a) (LR b)) = LR (a + b) +-- >>> :t f +-- f :: Num a => RTree 1 a -> RTree 0 a +-- >>> f (BR (LR 1) (LR 2)) +-- 3 +pattern BR :: RTree d a -> RTree d a -> RTree (d+1) a +pattern BR l r <- ((\t -> (tsplit t)) -> (l,r)) + where + BR l r = BR_ l r diff --git a/html-test/src/BundledPatterns2.hs b/html-test/src/BundledPatterns2.hs new file mode 100644 index 00000000..5e9a83a7 --- /dev/null +++ b/html-test/src/BundledPatterns2.hs @@ -0,0 +1,10 @@ +{-# LANGUAGE DataKinds, GADTs, KindSignatures, PatternSynonyms, TypeOperators, + ViewPatterns #-} +module BundledPatterns2 (Vec((:>), Empty), RTree(..)) where + +import GHC.TypeLits + +import BundledPatterns + +pattern Empty :: Vec 0 a +pattern Empty <- Nil |