[GHC] #15613: GHCi command, tracing steps of instance resolution for Constraint or expression

GHC ghc-devs at haskell.org
Thu Sep 6 19:51:44 UTC 2018


#15613: GHCi command, tracing steps of instance resolution for Constraint or
expression
-------------------------------------+-------------------------------------
           Reporter:  Iceland_jack   |             Owner:  (none)
               Type:  feature        |            Status:  new
  request                            |
           Priority:  lowest         |         Milestone:
          Component:  GHCi           |           Version:
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:  #15610
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 Another GHCi command (#15610) to trace the process of instance resolution
 for a constraint. This is already something people do by hand
 (ticket:10318#comment:6) and would be a great tool for explorers of
 Haskell

 This constraint ultimately boils down to lists being monoids and `Int`
 being a number

 {{{
 >> :elab Monoid (a -> b -> ([c], Sum Int))
 Monoid (a -> b -> ([c], Sum Int))
 ==> Monoid (b -> ([c], Sum Int))
   ==> Monoid ([c], Sum Int)
     ==> Monoid [c]
     ==> Monoid (Sum Int)
       ==> Num Int
 }}}

 If resolving the type class fails, it can pinpoint what caused it to fail

 {{{
 >> data A
 >> :elab Show (A, Int -> Int)
 Show (A, Int -> Int)
 <~bRZsz NO instance~>

 ==> Show A
   <NO instance>
 ==> Show (Int -> Int)
   <NO instance>
 }}}

 A verbose version can explain each step

 {{{
 >> :elab +v Monoid (a -> b -> ([c], Sum Int)
 Monoid (a -> b -> ([c], Sum Int)) -- Monoid b => Monoid (a -> b)
 (‘GHC.Base’)
 ==> Monoid (b -> ([c], Sum Int))  -- Monoid b => Monoid (a -> b)
 (‘GHC.Base’)
   ==> Monoid ([c], Sum Int)       -- Monoid b => Monoid (a -> b)
 (‘GHC.Base’)
     ==> Monoid [c]                --             Monoid [a]
 (‘GHC.Base’)
     ==> Monoid (Sum Int)          -- Num    a => Monoid (Sum a)
 (‘Data.Monoid’)
       ==> Num Int                 --             Num Int
 (‘GHC.Num’)
 }}}

 {{{
 >> :elab +v Num (Int, Float, Rational)
 Num (Int, Float, Rational) --  (Num a, Num b, Num c) => Num (a, b, c)
 (‘Data.NumInstances.Tuple’)
 ==> Num Int                --                           Num Int
 (‘GHC.Num’)
 ==> Num Float              --                           Num Float
 (‘GHC.Float’)
 ==> Num Rational           -- type Rational = Ratio Integer
 (‘GHC.Real’)
  =  Num (Ration Integer)   -- Integral a => Num (Ratio a)
 (‘GHC.Real’)
   ==> Integral Integer     --                           Integral Integer
 (‘GHC.Real’)
 }}}

 ----

 Not the same idea but similar. Listing instance resolution that takes
 place in an expression

 {{{
 >> :elab (+) @Int
 from: (+) @Int
   Num Int
 }}}
 {{{
 >> :elab2 comparing (length @[]) <> compare
 from: length @[]
   Foldable []

 from: comparing (length @[])
   Ord Int

 from: comparing (length @[]) <> compare
   Monoid ([a] -> [a] -> Ordering)
   ==> Monoid ([a] -> Ordering)
     ==> Monoid Ordering
 }}}
 {{{
 >> :elab2 ask 'a'
 from: ask 'a'
   MonadReader Char ((->) m)
   ==> MonadReader Char ((->) Char)
 }}}

 not sure about that last one, or how to visualize them but I think it
 gives the right idea.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15613>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list