[GHC] #13772: Cannot put HasCallStack on instances

#13772: Cannot put HasCallStack on instances -------------------------------------+------------------------------------- Reporter: augustss | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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: -------------------------------------+------------------------------------- I'd like to get stack traces even when I'm using methods from a class, but I don't seen to be able to put HasCallStack in instance declarations. See attached code. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13772 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13772: Cannot put HasCallStack on instances -------------------------------------+------------------------------------- Reporter: augustss | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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 augustss): * Attachment "CallStack.hs" added. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13772 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13772: Cannot put HasCallStack on instances -------------------------------------+------------------------------------- Reporter: augustss | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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 Iceland_jack): * cc: Iceland_jack (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13772#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13772: Cannot put HasCallStack on instances -------------------------------------+------------------------------------- Reporter: augustss | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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 simonpj): You can put implicit-parameter constraints on the methods, but not on the instance. If the instance had implicit-parameter constraints it'd become voisible exactly where the constraint was solved. So currently it's by design. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13772#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13772: Cannot put HasCallStack on instances -------------------------------------+------------------------------------- Reporter: augustss | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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 augustss): So can you explain where I should put my HasCallstack constraint in my Monoid instance? I'd like to get a call stack when mempty is used and it calls error. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13772#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13772: Cannot put HasCallStack on instances -------------------------------------+------------------------------------- Reporter: augustss | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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 simonpj): {{{ foo :: Monoid a => (a,a) foo = (mempty, mempty) bar :: Tree a bar = fst foo }}} You say you want a `HasCallStack` constraint just on the `Tree` instance of `mempty`. But I don't think you can do that. The call site of `mempty` is in `foo`, which is polymorhpic, works for any instance. Only in `bar` do we beome specific to the `Tree` instance. It'd be fine if you wanted to say {{{ class Monoid a where mempty :: HasCallStack => a ... }}} but I doubt you do. I don't see how to achieve what you want. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13772#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13772: Cannot put HasCallStack on instances -------------------------------------+------------------------------------- Reporter: augustss | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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 Iceland_jack): I am not very familiar with `HasCallStack` but it is possible to go from `ImplicitParams` to kmett's reflection library, I don't know where you would call [https://hackage.haskell.org/package/reflection-2.1.2/docs /Data-Reflection.html#v:reify reify] but it may help: {{{#!hs import Data.Proxy import GHC.Stack import Data.Reflection import Data.Monoid hiding ((<>)) import Data.Semigroup newtype WithClassStack s a = WCS a instance Semigroup a => Semigroup (WithClassStack s a) where WCS a <> WCS b = WCS (a <> b) instance (Semigroup a, Reifies s CallStack) => Monoid (WithClassStack s a) where mempty = error "No mempty!" where ?callStack = reflect (Proxy @s) mappend = (<>) }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13772#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13772: Cannot put HasCallStack on instances -------------------------------------+------------------------------------- Reporter: augustss | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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 saurabhnanda): Commenting to be notified of future discussion. (is there a better way to do this?) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13772#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13772: Cannot put HasCallStack on instances -------------------------------------+------------------------------------- Reporter: augustss | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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 saurabhnanda): * cc: saurabhnanda (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13772#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC