[GHC] #11661: Missing MonadFail instance for Q monad from TemplateHaskell
#11661: Missing MonadFail instance for Q monad from TemplateHaskell -------------------------------------+------------------------------------- Reporter: PeterTrsko | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Template | Version: 8.0.1-rc2 Haskell | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Since GHC 8.0.1 introduces MonadFailDesugaring one would expect Q monad to have an instance for MonadFail. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11661> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11661: Missing MonadFail instance for Q monad from TemplateHaskell -------------------------------------+------------------------------------- Reporter: PeterTrsko | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.0.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by hvr): Yes... I have been wondering for some time already (which is the reason there is no `MonadFail` instance yet) how to properly define one given : {{{#!hs class Monad m => Quasi m where -- ... newtype Q a = Q { unQ :: forall m. Quasi m => m a } instance Monad Q where -- ... fail s = report True s >> Q (fail "Q monad failure") }}} Now obviously we can't {{{#!hs instance Fail.MonadFail Q where -- ... fail = Control.Monad.fail }}} as that would call `Q`'s inner `Monad(fail)`, whereas we'd need it to call `Q`'s inner `MonadFail(fail)` which would require changing `Quasi`'s superclass, and I'm not sure that's appropriate. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11661#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11661: Missing MonadFail instance for Q monad from TemplateHaskell -------------------------------------+------------------------------------- Reporter: PeterTrsko | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.0.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): Well, you needn't necessarily change the context of `Quasi`; you could also add the constraint to `Q`. That being said, I'm not sure whether this is much better. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11661#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11661: Missing MonadFail instance for Q monad from TemplateHaskell -------------------------------------+------------------------------------- Reporter: PeterTrsko | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.0.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * cc: goldfire (added) -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11661#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11661: Missing MonadFail instance for Q monad from TemplateHaskell -------------------------------------+------------------------------------- Reporter: PeterTrsko | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.0.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by hvr): Btw, who is allowed to construct a `Q` value anyway? Are users of the `template-haskell` library allowed to, or is it only sensible for GHC to construct a Q value? -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11661#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11661: Missing MonadFail instance for Q monad from TemplateHaskell -------------------------------------+------------------------------------- Reporter: PeterTrsko | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.0.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by quchen): The question is, what do we gain? It would not be clear why Quasi has a MonadFail superclass, and I cannot imagine many functions might want to make use of Q's `fail`. Are we in danger of breaking any code because `fail` is removed from `Monad`, does TH rely on its existence? Maybe we should fix those cases instead. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11661#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11661: Missing MonadFail instance for Q monad from TemplateHaskell -------------------------------------+------------------------------------- Reporter: PeterTrsko | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.0.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by rwbarton): `fail :: String -> Q a` is the standard way for Template Haskell code to report a fatal error. (Say you are writing a quasiquoter for regular expressions, and the regular expression is ill-formed.) See http://hackage.haskell.org/package/template-haskell-2.10.0.0/docs /Language-Haskell-TH.html#v:reportError. `error :: String -> Q a` also works, sort of. But the error is reported differently by GHC ("Exception when trying to run compile-time code:"). `recover :: Q a -> Q a -> Q a` recovers from `fail`, but obviously not `error`. I don't know whether anyone actually uses `recover` though. I don't really understand all the issues around this `MonadFail` stuff but `Q`'s `fail` isn't something we should just sweep under the rug. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11661#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11661: Missing MonadFail instance for Q monad from TemplateHaskell -------------------------------------+------------------------------------- Reporter: PeterTrsko | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.0.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by PeterTrsko): Seems that `fail` is "integral part" of the `Q` monad and `fail` is part of its contract with the user. The same goes for `Quasy` type class. See e.g. `qReport` and `qRecover`. In my opinion, the only way to correctly preserve the same semantics, under `MonadFailDesugaring`, is to put `MonadFail` as a superclass of `Quasy`. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11661#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11661: Missing MonadFail instance for Q monad from TemplateHaskell -------------------------------------+------------------------------------- Reporter: PeterTrsko | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.0.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): I use `fail` in the `Q` monad and `recover` (in singletons). They are useful. I think adding a `MonadFail` superclass is the right way to go. User- defined instances of `Quasi` are rare. And TH generally undergoes quite a bit of churn between releases, so we certainly don't need to worry about the 3-release stability policy. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11661#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11661: Missing MonadFail instance for Q monad from TemplateHaskell -------------------------------------+------------------------------------- Reporter: PeterTrsko | Owner: Type: bug | Status: patch Priority: normal | Milestone: 8.0.1 Component: Template Haskell | Version: 8.0.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): phab:D1982 Wiki Page: | -------------------------------------+------------------------------------- Changes (by hvr): * status: new => patch * differential: => phab:D1982 * milestone: => 8.0.1 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11661#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11661: Missing MonadFail instance for Q monad from TemplateHaskell -------------------------------------+------------------------------------- Reporter: PeterTrsko | Owner: Type: bug | Status: patch Priority: normal | Milestone: 8.0.1 Component: Template Haskell | Version: 8.0.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): phab:D1982 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Herbert Valerio Riedel <hvr@…>): In [changeset:"1c76e1686bd4291556ae9357151f256c805b4b5d/ghc" 1c76e16/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="1c76e1686bd4291556ae9357151f256c805b4b5d" template-haskell: define `MonadFail Q` instance When `MonadFail`is available, this patch makes `MonadFail` a superclass of `Quasi`, and `Q` an instance of `MonadFail`. NB: Since f16ddcee0c64a92ab911a7841a8cf64e3ac671fd, we need to be able to compile `template-haskell` with stage0 compilers that don't provide a `MonadFail` class yet. Once we reach GHC 8.3 development we can drop the CPP conditionals again. Addresses #11661 Reviewed By: bgamari, goldfire Differential Revision: https://phabricator.haskell.org/D1982 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11661#comment:10> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11661: Missing MonadFail instance for Q monad from TemplateHaskell -------------------------------------+------------------------------------- Reporter: PeterTrsko | Owner: Type: bug | Status: closed Priority: normal | Milestone: 8.0.1 Component: Template Haskell | Version: 8.0.1-rc2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): phab:D1982 Wiki Page: | -------------------------------------+------------------------------------- Changes (by hvr): * status: patch => closed * resolution: => fixed Comment: Merged to `ghc-8.0` via 35b747fcde36bdc96e533bd1c3f02d81845453c2 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11661#comment:11> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC