debug icon indicating copy to clipboard operation
debug copied to clipboard

Apply to nested lambdas/functions

Open ndmitchell opened this issue 8 years ago • 10 comments

Currently only top-level declarations are trapped. However, it should be anything that looks lambda-like, so anything nested as well. e.g.

foo x y = ...
   where
      bar x y = ...

Should annotate both foo and bar.

ndmitchell avatar Dec 17 '17 21:12 ndmitchell

This is not immediately useful, because of free variables. The TH wrapper would need to eliminate them, probably via closure conversion or lambda lifting, so not trivial.

pepeiborra avatar Dec 25 '17 11:12 pepeiborra

It doesn't need to do lambda lifting - as long as it captures the variables again in the lambda. E.g.

foo x y = bar 1 + bar 2
   where bar z = ...

Could become:

foo x y = bar 1 + bar 2
   where bar (var "z" -> z) = var_ "x" x $ var_ "y" y $ ...

So you are recording x and y in the lambda, but don't have to eliminate them.

ndmitchell avatar Dec 29 '17 00:12 ndmitchell

I'm going to start looking at this now...

marklnichols avatar Feb 15 '18 17:02 marklnichols

I started by looking at what currently happens with your example above. This output is based on calling the function where_1 with params 5 and 7:

image

What is displayed seems reasonably clear (though the variables z vs z' is maybe a little confusing).

So what would we prefer to see instead?

marklnichols avatar Feb 18 '18 12:02 marklnichols

I just noticed that the operator (*) is not displayed -- a more complicated example will probably show the declarations after the 'where' are not being fully explored.

marklnichols avatar Feb 18 '18 13:02 marklnichols

Regarding the last comment about the (*) operator, I have a fix for that I'll try to put in tomorrow.

marklnichols avatar Feb 20 '18 23:02 marklnichols

This should be fixed with the PR just submitted.

marklnichols avatar Feb 21 '18 13:02 marklnichols

The part that is now 'fixed' is the discovery of function application after the 'where'. For the overall issue, though, I was looking for input as to what still needs to be done. See the example above.

marklnichols avatar Feb 22 '18 00:02 marklnichols

Hi,

(debug package for lts-11.3)

I am not getting any traces of the inner go function in this example:

{-# LANGUAGE TemplateHaskell, ViewPatterns, PartialTypeSignatures #-}
{-# OPTIONS_GHC -Wno-partial-type-signatures #-}

module Main where

import Data.Array
import Data.List
import Control.Monad
import Text.Printf

import Debug

debug [d|
      fs :: [[Int] -> Int]
      fs = [ const 1
            , succ . (!! 0)
            , succ . (!! 1)
            , succ . (!! 2)
            ]

      loeb :: Functor f => f (f a -> a) -> f a
      loeb x = go where go = fmap ($ go) x

      testLoeb = print $ show $ loeb fs
      |]

Instead, only the one call to loeb is traced.

clojj avatar Apr 07 '18 22:04 clojj

Sorry to hear @clojj - thanks for the report, unfortunately I think all the authors of this project are busy on other things at the moment - but we'll certainly take a look once one of us returns!

ndmitchell avatar Apr 13 '18 14:04 ndmitchell