1. 20 Jul, 2015 2 commits
    • Luite Stegeman's avatar
      Do not treat prim and javascript imports as C imports in TH and QQ · 4cd008b6
      Luite Stegeman authored
      Reviewers: austin, hvr, goldfire, bgamari
      
      Reviewed By: bgamari
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D1070
      
      GHC Trac Issues: #10638
      4cd008b6
    • thomasw's avatar
      Support wild cards in TH splices · 49373ffe
      thomasw authored
      - Declaration splices: partial type signatures are fully supported in TH
        declaration splices.
      
        For example, the wild cards in the example below will unify with `Eq
      a`
        and `a -> a -> Bool`, as expected:
      
      ```
      [d| foo :: _ => _
          foo x y = x == y |]
      ```
      
      - Expression splices: anonymous and named wild cards are supported in
        expression signatures, but extra-constraints wild cards aren't. Just
        as is the case for regular expression signatures.
      
      ```
      [e | Just True :: _a _ |]
      ```
      
      - Typed expression splices: the same wildcards as in (untyped)
        expression splices are supported.
      
      - Pattern splices: TH doesn't support type signatures in pattern
        splices, consequently, partial type signatures aren't supported
        either.
      
      - Type splices: partial type signatures are only partially supported in
        type splices, specifically: only anonymous wild cards are allowed.
      
        So `[t| _ |]`, `[t| _ -> Maybe _ |]` will work, but `[t| _ => _ |]` or
        `[| _a |]` won't (without `-XNamedWildCards`, the latter will work as
        the named wild card is treated as a type variable).
      
        Normally, named wild cards are collected before renaming a (partial)
        type signature. However, TH type splices are run during renaming, i.e.
        after the initial traversal, leading to out of scope errors for named
        wild cards. We can't just extend the initial traversal to collect the
        named wild cards in TH type splices, as we'd need to expand them,
        which is supposed to happen only once, during renaming.
      
        Similarly, the extra-constraints wild card is handled right before
        renaming too, and is therefore also not supported in a TH type splice.
        Another reason not to support extra-constraints wild cards in TH type
        splices is that a single signature can contain many TH type splices,
        whereas it mustn't contain more than one extra-constraints wild card.
        Enforcing would this be hard the way things are currently organised.
      
        Anonymous wild cards pose no problem, because they start without names
        and are given names during renaming. These names are collected right
        after renaming. The names generated for anonymous wild cards in TH
        type splices will thus be collected as well.
      
        With a more invasive refactoring of the renaming, partial type
        signatures could be fully supported in TH type splices. As only
        anonymous wild cards have been requested so far, these small changes
        satisfying this request will do for now. Also don't forget that a TH
        declaration splices support all kinds of wild cards.
      
      - Extra-constraints wild cards were silently ignored in expression and
        pattern signatures, appropriate error messages are now generated.
      
      Test Plan: run new tests
      
      Reviewers: austin, goldfire, adamgundry, bgamari
      
      Reviewed By: goldfire, adamgundry, bgamari
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D1048
      
      GHC Trac Issues: #10094, #10548
      49373ffe
  2. 16 Jul, 2015 1 commit
    • RyanGlScott's avatar
      Handle Char#, Addr# in TH quasiquoter (fixes #10620) · 2c9de9c9
      RyanGlScott authored
      DsMeta does not attempt to handle quasiquoted Char# or Addr# values,
      which causes expressions like `$([| 'a'# |])` or `$([| "abc"# |])` to
      fail
      with an `Exotic literal not (yet) handled by Template Haskell` error.
      
      To fix this, the API of `template-haskell` had to be changed so that
      `Lit`
      now has an extra constructor `CharPrimL` (a `StringPrimL` constructor
      already
      existed, but it wasn't used). In addition, `DsMeta` has to manipulate
      `CoreExpr`s directly that involve `Word8`s. In order to do this,
      `Word8` had
      to be added as a wired-in type to `TysWiredIn`.
      
      Actually converting from `HsCharPrim` and `HsStringPrim` to `CharPrimL`
      and
      `StringPrimL`, respectively, is pretty straightforward after that, since
      both `HsCharPrim` and `CharPrimL` use `Char` internally, and
      `HsStringPrim`
      uses a `ByteString` internally, which can easily be converted to
      `[Word8]`,
      which is what `StringPrimL` uses.
      
      Reviewers: goldfire, austin, simonpj, bgamari
      
      Reviewed By: simonpj, bgamari
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D1054
      
      GHC Trac Issues: #10620
      2c9de9c9
  3. 01 Jun, 2015 1 commit
    • Alan Zimmerman's avatar
      ApiAnnotations : strings in warnings do not return SourceText · e6191d1c
      Alan Zimmerman authored
      Summary:
      The strings used in a WARNING pragma are captured via
      
          strings :: { Located ([AddAnn],[Located FastString]) }
              : STRING { sL1 $1 ([],[L (gl $1) (getSTRING $1)]) }
          ..
      
      The STRING token has a method getSTRINGs that returns the original
      source text for a string.
      
      A warning of the form
      
          {-# WARNING Logic
                    , mkSolver
                    , mkSimpleSolver
                    , mkSolverForLogic
                    , solverSetParams
                    , solverPush
                    , solverPop
                    , solverReset
                    , solverGetNumScopes
                    , solverAssertCnstr
                    , solverAssertAndTrack
                    , solverCheck
                    , solverCheckAndGetModel
                    , solverGetReasonUnknown
                    "New Z3 API support is still incomplete and fragile: \
                    \you may experience segmentation faults!"
            #-}
      
      returns the concatenated warning string rather than the original source.
      
      This patch now deals with all remaining instances of getSTRING to bring
      in a SourceText for each.
      
      This updates the haddock submodule as well, for the AST change.
      
      Test Plan: ./validate
      
      Reviewers: hvr, austin, goldfire
      
      Reviewed By: austin
      
      Subscribers: bgamari, thomie, mpickering
      
      Differential Revision: https://phabricator.haskell.org/D907
      
      GHC Trac Issues: #10313
      e6191d1c
  4. 21 May, 2015 1 commit
    • Alan Zimmerman's avatar
      ApiAnnotations : AST version of nested forall loses forall annotation · c553e980
      Alan Zimmerman authored
      Summary:
      When parsing
      
          {-# LANGUAGE ScopedTypeVariables #-}
      
          extremumNewton :: forall tag. forall tag1.
                             tag -> tag1 -> Int
          extremumNewton = undefined
      
      the parser creates nested HsForAllTy's for the two forall statements.
      
      These get flattened into a single one in `HsTypes.mk_forall_ty`
      
      This patch removes the flattening, so that API Annotations are not lost in the
      process.
      
      Test Plan: ./validate
      
      Reviewers: goldfire, austin, simonpj
      
      Reviewed By: simonpj
      
      Subscribers: bgamari, mpickering, thomie, goldfire
      
      Differential Revision: https://phabricator.haskell.org/D836
      
      GHC Trac Issues: #10278, #10315, #10354, #10363
      c553e980
  5. 18 May, 2015 1 commit
    • Simon Peyton Jones's avatar
      Refactor tuple constraints · ffc21506
      Simon Peyton Jones authored
      Make tuple constraints be handled by a perfectly ordinary
      type class, with the component constraints being the
      superclasses:
          class (c1, c2) => (c2, c2)
      
      This change was provoked by
      
        #10359  inability to re-use a given tuple
                constraint as a whole
      
        #9858   confusion between term tuples
                and constraint tuples
      
      but it's generally a very nice simplification. We get rid of
       -  In Type, the TuplePred constructor of PredTree,
          and all the code that dealt with TuplePreds
       -  In TcEvidence, the constructors EvTupleMk, EvTupleSel
      
      See Note [How tuples work] in TysWiredIn.
      
      Of course, nothing is ever entirely simple. This one
      proved quite fiddly.
      
      - I did quite a bit of renaming, which makes this patch
        touch a lot of modules. In partiuclar tupleCon -> tupleDataCon.
      
      - I made constraint tuples known-key rather than wired-in.
        This is different to boxed/unboxed tuples, but it proved
        awkward to have all the superclass selectors wired-in.
        Easier just to use the standard mechanims.
      
      - While I was fiddling with known-key names, I split the TH Name
        definitions out of DsMeta into a new module THNames.  That meant
        that the known-key names can all be gathered in PrelInfo, without
        causing module loops.
      
      - I found that the parser was parsing an import item like
            T( .. )
        as a *data constructor* T, and then using setRdrNameSpace to
        fix it.  Stupid!  So I changed the parser to parse a *type
        constructor* T, which means less use of setRdrNameSpace.
      
        I also improved setRdrNameSpace to behave better on Exact Names.
        Largely on priciple; I don't think it matters a lot.
      
      - When compiling a data type declaration for a wired-in thing like
        tuples (,), or lists, we don't really need to look at the
        declaration.  We have the wired-in thing!  And not doing so avoids
        having to line up the uniques for data constructor workers etc.
        See Note [Declarations for wired-in things]
      
      - I found that FunDeps.oclose wasn't taking superclasses into
        account; easily fixed.
      
      - Some error message refactoring for invalid constraints in TcValidity
      
      - Haddock needs to absorb the change too; so there is a submodule update
      ffc21506
  6. 14 May, 2015 1 commit
    • Austin Seipp's avatar
      Revert multiple commits · 3cf8ecdc
      Austin Seipp authored
      This reverts multiple commits from Simon:
      
        - 04a484ea Test Trac #10359
        - a9ccd37a Test Trac #10403
        - c0aae6f6 Test Trac #10248
        - eb6ca851 Make the "matchable-given" check happen first
        - ca173aa3 Add a case to checkValidTyCon
        - 51cbad15 Update haddock submodule
        - 6e1174da Separate transCloVarSet from fixVarSet
        - a8493e03 Fix imports in HscMain (stage2)
        - a154944b Two wibbles to fix the build
        - 5910a1bc Change in capitalisation of error msg
        - 130e93aa Refactor tuple constraints
        - 8da785d5 Delete commented-out line
      
      These break the build by causing Haddock to fail mysteriously when
      trying to examine GHC.Prim it seems.
      3cf8ecdc
  7. 13 May, 2015 1 commit
    • Simon Peyton Jones's avatar
      Refactor tuple constraints · 130e93aa
      Simon Peyton Jones authored
      Make tuple constraints be handled by a perfectly ordinary
      type class, with the component constraints being the
      superclasses:
          class (c1, c2) => (c2, c2)
      
      This change was provoked by
      
        #10359  inability to re-use a given tuple
                constraint as a whole
      
        #9858   confusion between term tuples
                and constraint tuples
      
      but it's generally a very nice simplification. We get rid of
       -  In Type, the TuplePred constructor of PredTree,
          and all the code that dealt with TuplePreds
       -  In TcEvidence, the constructors EvTupleMk, EvTupleSel
      
      See Note [How tuples work] in TysWiredIn.
      
      Of course, nothing is ever entirely simple. This one
      proved quite fiddly.
      
      - I did quite a bit of renaming, which makes this patch
        touch a lot of modules. In partiuclar tupleCon -> tupleDataCon.
      
      - I made constraint tuples known-key rather than wired-in.
        This is different to boxed/unboxed tuples, but it proved
        awkward to have all the superclass selectors wired-in.
        Easier just to use the standard mechanims.
      
      - While I was fiddling with known-key names, I split the TH Name
        definitions out of DsMeta into a new module THNames.  That meant
        that the known-key names can all be gathered in PrelInfo, without
        causing module loops.
      
      - I found that the parser was parsing an import item like
            T( .. )
        as a *data constructor* T, and then using setRdrNameSpace to
        fix it.  Stupid!  So I changed the parser to parse a *type
        constructor* T, which means less use of setRdrNameSpace.
      
        I also improved setRdrNameSpace to behave better on Exact Names.
        Largely on priciple; I don't think it matters a lot.
      
      - When compiling a data type declaration for a wired-in thing like
        tuples (,), or lists, we don't really need to look at the
        declaration.  We have the wired-in thing!  And not doing so avoids
        having to line up the uniques for data constructor workers etc.
        See Note [Declarations for wired-in things]
      
      - I found that FunDeps.oclose wasn't taking superclasses into
        account; easily fixed.
      
      - Some error message refactoring for invalid constraints in TcValidity
      130e93aa
  8. 06 May, 2015 2 commits
  9. 04 May, 2015 1 commit
    • Adam Gundry's avatar
      Permit empty closed type families · 4efa4213
      Adam Gundry authored
      Fixes #9840 and #10306, and includes an alternative resolution to #8028.
      This permits empty closed type families, and documents them in the user
      guide. It updates the Haddock submodule to support the API change.
      
      Test Plan: Added `indexed-types/should_compile/T9840` and updated
      `indexed-types/should_fail/ClosedFam4` and `th/T8028`.
      
      Reviewers: austin, simonpj, goldfire
      
      Reviewed By: goldfire
      
      Subscribers: bgamari, jstolarek, thomie, goldfire
      
      Differential Revision: https://phabricator.haskell.org/D841
      
      GHC Trac Issues: #9840, #10306
      4efa4213
  10. 10 Feb, 2015 1 commit
  11. 16 Jan, 2015 1 commit
    • Alan Zimmerman's avatar
      API Annotations tweaks. · 11881ec6
      Alan Zimmerman authored
      Summary:
      HsTyLit now has SourceText
      
      Update documentation of HsSyn to reflect which annotations are attached to which element.
      
      Ensure that the parser always keeps HsSCC and HsTickPragma values, to
      be ignored in the desugar phase if not needed
      
      Bringing in SourceText for pragmas
      
      Add Location in NPlusKPat
      
      Add Location in FunDep
      
      Make RecCon payload Located
      
      Explicitly add AnnVal to RdrName where it is compound
      
      Add Location in IPBind
      
      Add Location to name in IEThingAbs
      
      Add Maybe (Located id,Bool) to Match to track fun_id,infix
        This includes converting Match into a record and adding a note about why
        the fun_id needs to be replicated in the Match.
      
      Add Location in KindedTyVar
      
      Sort out semi-colons for parsing
      
        - import statements
        - stmts
        - decls
        - decls_cls
        - decls_inst
      
      This updates the haddock submodule.
      
      Test Plan: ./validate
      
      Reviewers: hvr, austin, goldfire, simonpj
      
      Reviewed By: simonpj
      
      Subscribers: thomie, carter
      
      Differential Revision: https://phabricator.haskell.org/D538
      11881ec6
  12. 08 Jan, 2015 1 commit
    • Simon Peyton Jones's avatar
      Improve HsBang · 9564bb8c
      Simon Peyton Jones authored
      Provoked by questions from Johan
      
       - Improve comments, fix misleading stuff
       - Add commented synonyms for HsSrcBang, HsImplBang, and use them throughout
       - Rename HsUserBang to HsSrcBang
       - Rename dataConStrictMarks to dataConSrcBangs
                dataConRepBangs    to dataConImplBangs
      
      This renaming affects Haddock in a trivial way, hence submodule update
      9564bb8c
  13. 16 Dec, 2014 1 commit
  14. 10 Dec, 2014 1 commit
  15. 03 Dec, 2014 1 commit
  16. 28 Nov, 2014 1 commit
  17. 21 Nov, 2014 3 commits
  18. 20 Nov, 2014 1 commit
  19. 12 Nov, 2014 4 commits
  20. 07 Oct, 2014 1 commit
    • glguy's avatar
      Add support for LINE pragma in template-haskell · adcb9dbc
      glguy authored
      Summary:
      Provide a way to generate {-# LINE #-} pragmas when generating
      Decs in Template Haskell. This allows more meaningful line
      numbers to be reported in compile-time errors for dynamically
      generated code.
      
      Test Plan: Run test suite
      
      Reviewers: austin, hvr
      
      Reviewed By: austin
      
      Subscribers: hvr, simonmar, ezyang, carter, thomie
      
      Differential Revision: https://phabricator.haskell.org/D299
      adcb9dbc
  21. 09 Sep, 2014 1 commit
    • Austin Seipp's avatar
      Make Applicative a superclass of Monad · d94de872
      Austin Seipp authored
      Summary:
      This includes pretty much all the changes needed to make `Applicative`
      a superclass of `Monad` finally. There's mostly reshuffling in the
      interests of avoid orphans and boot files, but luckily we can resolve
      all of them, pretty much. The only catch was that
      Alternative/MonadPlus also had to go into Prelude to avoid this.
      
      As a result, we must update the hsc2hs and haddock submodules.
      Signed-off-by: default avatarAustin Seipp <austin@well-typed.com>
      
      Test Plan: Build things, they might not explode horribly.
      
      Reviewers: hvr, simonmar
      
      Subscribers: simonmar
      
      Differential Revision: https://phabricator.haskell.org/D13
      d94de872
  22. 06 Sep, 2014 1 commit
  23. 21 Jul, 2014 1 commit
    • Edward Z. Yang's avatar
      Rename PackageId to PackageKey, distinguishing it from Cabal's PackageId. · 4bebab25
      Edward Z. Yang authored
      Summary:
      Previously, both Cabal and GHC defined the type PackageId, and we expected
      them to be roughly equivalent (but represented differently).  This refactoring
      separates these two notions.
      
      A package ID is a user-visible identifier; it's the thing you write in a
      Cabal file, e.g. containers-0.9.  The components of this ID are semantically
      meaningful, and decompose into a package name and a package vrsion.
      
      A package key is an opaque identifier used by GHC to generate linking symbols.
      Presently, it just consists of a package name and a package version, but
      pursuant to #9265 we are planning to extend it to record other information.
      Within a single executable, it uniquely identifies a package.  It is *not* an
      InstalledPackageId, as the choice of a package key affects the ABI of a package
      (whereas an InstalledPackageId is computed after compilation.)  Cabal computes
      a package key for the package and passes it to GHC using -package-name (now
      *extremely* misnamed).
      
      As an added bonus, we don't have to worry about shadowing anymore.
      
      As a follow on, we should introduce -current-package-key having the same role as
      -package-name, and deprecate the old flag.  This commit is just renaming.
      
      The haddock submodule needed to be updated.
      Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>
      
      Test Plan: validate
      
      Reviewers: simonpj, simonmar, hvr, austin
      
      Subscribers: simonmar, relrod, carter
      
      Differential Revision: https://phabricator.haskell.org/D79
      
      Conflicts:
      	compiler/main/HscTypes.lhs
      	compiler/main/Packages.lhs
      	utils/haddock
      4bebab25
  24. 15 Jul, 2014 1 commit
    • Simon Peyton Jones's avatar
      Entirely re-jig the handling of default type-family instances (fixes Trac #9063) · 9b8ba629
      Simon Peyton Jones authored
      In looking at Trac #9063 I decided to re-design the default
      instances for associated type synonyms.  Previously it was all
      jolly complicated, to support generality that no one wanted, and
      was arguably undesirable.
      
      Specifically
      
      * The default instance for an associated type can have only
        type variables on the LHS.  (Not type patterns.)
      
      * There can be at most one default instances declaration for
        each associated type.
      
      To achieve this I had to do a surprisingly large amount of refactoring
      of HsSyn, specifically to parameterise HsDecls.TyFamEqn over the type
      of the LHS patterns.
      
      That change in HsDecls has a (trivial) knock-on effect in Haddock, so
      this commit does a submodule update too.
      
      The net result is good though.  The code is simpler; the language
      specification is simpler.  Happy days.
      
      Trac #9263 and #9264 are thereby fixed as well.
      9b8ba629
  25. 30 Jun, 2014 1 commit
    • Iavor S. Diatchki's avatar
      Overlapable pragmas for individual instances (#9242) · 6290eead
      Iavor S. Diatchki authored
      Programmers may provide a pragma immediately after the `instance` keyword
      to control the overlap/incoherence behavior for individual instances.
      For example:
      
          instance {-# OVERLAP #-} C a where ...
      
      I chose this notation, rather than the other two outlined in the ticket
      for these reasons:
      
         1. Having the pragma after the type looks odd, I think.
         2. Having the pragma after there `where` does not work for
             stand-alone derived instances
      
      I have implemented 3 pragams:
      
         1. NO_OVERLAP
         2. OVERLAP
         3. INCOHERENT
      
      These correspond directly to the internal modes currently supported by
      GHC.  If a pragma is specified, it will be used no matter what flags are
      turned on.   For example, putting `NO_OVERLAP` on an instance will mark
      it as non-overlapping, even if `OVERLAPPIN_INSTANCES` is turned on for the
      module.
      6290eead
  26. 06 Jun, 2014 1 commit
    • Simon Peyton Jones's avatar
      Make the matcher and wrapper Ids in PatSyn into LocalIds, not GlobalIds · 7ac600d5
      Simon Peyton Jones authored
      This was a serious bug, exposed by Trac #9175.  The matcher and wrapper
      must be LocalIds, like record selectors and dictionary functions, for
      the reasons now documented in Note [Exported LocalIds] in Id.lhs
      
      In fixing this I found
       - PatSyn should have an Id inside it (apart from the wrapper and matcher)
         It should be a Name.  Hence psId --> psName, with knock-on consequences
      
       - Tidying of PatSyns in TidyPgm was wrong
      
       - The keep-alive set in Desugar.deSugar (now) doesn't need pattern synonyms
         in it
      
      I also cleaned up the interface to PatSyn a little, so there's a tiny knock-on
      effect in Haddock; hence the haddock submodule update.
      
      It's very hard to make a test for this bug, so I haven't.
      7ac600d5
  27. 05 Jun, 2014 1 commit
    • Simon Peyton Jones's avatar
      Fix egregious instantiation bug in matchOneConLike (fixing Trac #9023) · 0a55a3ca
      Simon Peyton Jones authored
      We simply weren't giving anything like the right instantiating types
      to patSynInstArgTys in matchOneConLike.
      
      To get these instantiating types would have involved matching the
      result type of the pattern synonym with the pattern type, which is
      tiresome.  So instead I changed ConPatOut so that instead of recording
      the type of the *whole* pattern (in old field pat_ty), it not records
      the *instantiating* types (in new field pat_arg_tys).  Then we canuse
      TcHsSyn.conLikeResTy to get the pattern type when needed.
      
      There are lots of knock-on incidental effects, but they mostly made
      the code simpler, so I'm happy.
      0a55a3ca
  28. 15 May, 2014 1 commit
    • Herbert Valerio Riedel's avatar
      Add LANGUAGE pragmas to compiler/ source files · 23892440
      Herbert Valerio Riedel authored
      In some cases, the layout of the LANGUAGE/OPTIONS_GHC lines has been
      reorganized, while following the convention, to
      
      - place `{-# LANGUAGE #-}` pragmas at the top of the source file, before
        any `{-# OPTIONS_GHC #-}`-lines.
      
      - Moreover, if the list of language extensions fit into a single
        `{-# LANGUAGE ... -#}`-line (shorter than 80 characters), keep it on one
        line. Otherwise split into `{-# LANGUAGE ... -#}`-lines for each
        individual language extension. In both cases, try to keep the
        enumeration alphabetically ordered.
        (The latter layout is preferable as it's more diff-friendly)
      
      While at it, this also replaces obsolete `{-# OPTIONS ... #-}` pragma
      occurences by `{-# OPTIONS_GHC ... #-}` pragmas.
      23892440
  29. 13 Apr, 2014 1 commit
  30. 04 Apr, 2014 1 commit
    • Simon Peyton Jones's avatar
      Simplify and tidy up the handling of tuple names · 750271e6
      Simon Peyton Jones authored
      This fixes Trac #8954.
      
      There were actually three places where tuple occ-names
      were parsed:
        - IfaceEnv.lookupOrigNameCache
        - Convert.isBuiltInOcc
        - OccName.isTupleOcc_maybe
      
      I combined all three into TysWiredIn.isBuiltInOcc_maybe
      Much nicer.
      750271e6
  31. 09 Feb, 2014 1 commit
  32. 20 Jan, 2014 1 commit
    • cactus's avatar
      Implement pattern synonyms · 4f8369bf
      cactus authored
      This patch implements Pattern Synonyms (enabled by -XPatternSynonyms),
      allowing y ou to assign names to a pattern and abstract over it.
      
      The rundown is this:
      
        * Named patterns are introduced by the new 'pattern' keyword, and can
          be either *unidirectional* or *bidirectional*. A unidirectional
          pattern is, in the simplest sense, simply an 'alias' for a pattern,
          where the LHS may mention variables to occur in the RHS. A
          bidirectional pattern synonym occurs when a pattern may also be used
          in expression context.
      
        * Unidirectional patterns are declared like thus:
      
              pattern P x <- x:_
      
          The synonym 'P' may only occur in a pattern context:
      
              foo :: [Int] -> Maybe Int
              foo (P x) = Just x
              foo _     = Nothing
      
        * Bidirectional patterns are declared like thus:
      
              pattern P x y = [x, y]
      
          Here, P may not only occur as a pattern, but also as an expression
          when given values for 'x' and 'y', i.e.
      
              bar :: Int -> [Int]
              bar x = P x 10
      
        * Patterns can't yet have their own type signatures; signatures are inferred.
      
        * Pattern synonyms may not be recursive, c.f. type synonyms.
      
        * Pattern synonyms are also exported/imported using the 'pattern'
          keyword in an import/export decl, i.e.
      
              module Foo (pattern Bar) where ...
      
          Note that pattern synonyms share the namespace of constructors, so
          this disambiguation is required as a there may also be a 'Bar'
          type in scope as well as the 'Bar' pattern.
      
        * The semantics of a pattern synonym differ slightly from a typical
          pattern: when using a synonym, the pattern itself is matched,
          followed by all the arguments. This means that the strictness
          differs slightly:
      
              pattern P x y <- [x, y]
      
              f (P True True) = True
              f _             = False
      
              g [True, True] = True
              g _            = False
      
          In the example, while `g (False:undefined)` evaluates to False,
          `f (False:undefined)` results in undefined as both `x` and `y`
          arguments are matched to `True`.
      
      For more information, see the wiki:
      
          https://ghc.haskell.org/trac/ghc/wiki/PatternSynonyms
          https://ghc.haskell.org/trac/ghc/wiki/PatternSynonyms/ImplementationReviewed-by: Simon Peyton Jones's avatarSimon Peyton Jones <simonpj@microsoft.com>
      Signed-off-by: default avatarAustin Seipp <austin@well-typed.com>
      4f8369bf
  33. 02 Dec, 2013 1 commit