summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorCale Gibbard <cgibbard@gmail.com>2020-10-07 02:31:36 -0400
committercgibbard <cgibbard@gmail.com>2020-12-31 13:05:42 -0500
commit9b563330203e209f5e0b687108f08ddf0d2f3177 (patch)
tree4e09fc2b8f4148daac8238bfb40d9352e2e29413 /docs
parent2113a1d600e579bb0f54a0526a03626f105c0365 (diff)
downloadhaskell-9b563330203e209f5e0b687108f08ddf0d2f3177.tar.gz
INLINE pragma for patterns (#12178)
Allow INLINE and NOINLINE pragmas to be used for patterns. Those are applied to both the builder and matcher (where applicable).
Diffstat (limited to 'docs')
-rw-r--r--docs/users_guide/exts/pattern_synonyms.rst34
1 files changed, 34 insertions, 0 deletions
diff --git a/docs/users_guide/exts/pattern_synonyms.rst b/docs/users_guide/exts/pattern_synonyms.rst
index abb7b82860..9415fb72b4 100644
--- a/docs/users_guide/exts/pattern_synonyms.rst
+++ b/docs/users_guide/exts/pattern_synonyms.rst
@@ -520,4 +520,38 @@ below:
*Main> g (False:undefined)
False
+Pragmas for pattern synonyms
+----------------------------
+
+The :ref:`inlinable-pragma`, :ref:`inline-pragma` and :ref:`noinline-pragma` are supported for pattern
+synonyms. For example: ::
+
+ patternInlinablePattern x = [x]
+ {-# INLINABLE InlinablePattern #-}
+ pattern InlinedPattern x = [x]
+ {-# INLINE InlinedPattern #-}
+ pattern NonInlinedPattern x = [x]
+ {-# NOINLINE NonInlinedPattern #-}
+
+As with other ``INLINABLE``, ``INLINE`` and ``NOINLINE`` pragmas, it's possible to specify
+to which phase the pragma applies: ::
+
+ pattern Q x = [x]
+ {-# NOINLINE[1] Q #-}
+
+The pragmas are applied both when the pattern is used as a matcher, and as a
+data constructor. For explicitly bidirectional pattern synonyms, the pragma
+must be at top level, not nested in the where clause. For example, this won't compile: ::
+
+ pattern HeadC x <- x:xs where
+ HeadC x = [x]
+ {-# INLINE HeadC #-}
+
+but this will: ::
+
+ pattern HeadC x <- x:xs where
+ HeadC x = [x]
+ {-# INLINE HeadC #-}
+When no pragma is provided for a pattern, the inlining decision is made by
+GHC's own inlining heuristics.