Loading ...
Sorry, an error occurred while loading the content.

How to read trace output

Expand Messages
  • cugf_0956
    Is there a place where it is described how to decrypt trace output? Or may be you can tell me what all this mean? fold fold -- fold*
    Message 1 of 2 , Aug 6, 2007
    • 0 Attachment
      Is there a place where it is described how to decrypt "trace" output?
      Or may be you can tell me what all this mean?

      fold <-- <fun>
      fold --> <fun>
      fold* <-- <poly>
      fold* --> <fun>
      fold** <--
      Node (Node (Leaf, <poly>, Leaf), <poly>,
      Node (Node (Leaf, <poly>, Node (Leaf, <poly>, Leaf)), <poly>,
      Node (Leaf, <poly>, Leaf)))

      What is the difference between fold and fold* and fold**, is it a
      reference to 3 different instantiations of the same function?
      What is <poly>?
      I guess "<--" means parameter in and "-->" - return value?

      Are there any other symbols I should be aware of?

      Thanks,
      MH
    • William D. Neumann
      ... No. fold* is the function resulting from applying fold to its first argument, and fold** is fold with the first two arguments applied (or fold* with the
      Message 2 of 2 , Aug 6, 2007
      • 0 Attachment
        On Mon, 6 Aug 2007, cugf_0956 wrote:

        > Is there a place where it is described how to decrypt "trace" output?
        > Or may be you can tell me what all this mean?
        >
        > fold <-- <fun>
        > fold --> <fun>
        > fold* <-- <poly>
        > fold* --> <fun>
        > fold** <--
        > Node (Node (Leaf, <poly>, Leaf), <poly>,
        > Node (Node (Leaf, <poly>, Node (Leaf, <poly>, Leaf)), <poly>,
        > Node (Leaf, <poly>, Leaf)))
        >
        > What is the difference between fold and fold* and fold**, is it a
        > reference to 3 different instantiations of the same function?

        No. fold* is the function resulting from applying fold to its first
        argument, and fold** is fold with the first two arguments applied (or
        fold* with the next argument applied). For example, consider:

        # let rec fib n a b =
        if n = 0 then a else fib (n-1) (a + b) a;;
        val fib : int -> int -> int -> int = <fun>
        # #trace fib;;
        fib is now traced.
        # fib 3 1 0;;
        fib <-- 3
        fib --> <fun>
        fib* <-- 1
        fib* --> <fun>
        fib** <-- 0
        fib <-- 2
        fib --> <fun>
        fib* <-- 1
        fib* --> <fun>
        fib** <-- 1
        fib <-- 1
        fib --> <fun>
        fib* <-- 2
        fib* --> <fun>
        fib** <-- 1
        fib <-- 0
        fib --> <fun>
        fib* <-- 3
        fib* --> <fun>
        fib** <-- 2
        fib** --> 3
        fib** --> 3
        fib** --> 3
        fib** --> 3
        - : int = 3

        > What is <poly>?

        poly indicates that a value is being passed into a polymorphic parameter
        of the function. For example, using your fold function:

        # type 'a tree = Leaf | Node of 'a tree * 'a * 'a tree;;
        type 'a tree = Leaf | Node of 'a tree * 'a * 'a tree
        # let rec fold glue lfval tr = (* Divide/conquer/glue on trees *)
        match tr with
        Leaf -> lfval
        | Node(l,v,r) -> glue (fold glue lfval l) v (fold glue lfval r);;

        val fold : ('a -> 'b -> 'a -> 'a) -> 'a -> 'b tree -> 'a = <fun>
        # #trace fold;;
        fold is now traced.
        # let fold' = fold (fun l v r -> l + v + r);;
        fold <-- <fun>
        fold --> <fun>
        val fold' : int -> int tree -> int = <fun>
        # #trace fold';;
        fold' is now traced.
        # fold' 0;;
        fold' <-- 0
        fold* <-- <poly>
        fold* --> <fun>
        fold' --> <fun>
        - : int tree -> int = <fun>

        Note that fold' knows it's getting an int, so its trace shows it getting a
        0, but once fold' passes it on to fold (where the type on that argument is
        'a, not int), we get <poly> printed as the value.

        If you know what types are going into the function, you can use type
        annotations to specialize the function and get rid of the <poly>. E.g.:

        # let f a b c d e = d;;
        val f : 'a -> 'b -> 'c -> 'd -> 'e -> 'd = <fun>
        # #trace f;;
        f is now traced.
        # f 0 1 2 3 4;;
        f <-- <poly>
        f --> <fun>
        f* <-- <poly>
        f* --> <fun>
        f** <-- <poly>
        f** --> <fun>
        f*** <-- <poly>
        f*** --> <fun>
        f**** <-- <poly>
        f**** --> <poly>
        - : int = 3
        # let f' a b (c : int) d e = d;;
        val f' : 'a -> 'b -> int -> 'c -> 'd -> 'c = <fun>
        # #trace f';;
        f' is now traced.
        # f' 0 1 2 3 4;;
        f' <-- <poly>
        f' --> <fun>
        f'* <-- <poly>
        f'* --> <fun>
        f'** <-- 2
        f'** --> <fun>
        f'*** <-- <poly>
        f'*** --> <fun>
        f'**** <-- <poly>
        f'**** --> <poly>
        - : int = 3


        > I guess "<--" means parameter in and "-->" - return value?

        Yes.

        > Are there any other symbols I should be aware of?

        Well, I know that there is <obj> for representing objects, but that's all
        I can recall. I don't use tracing very often.

        William D. Neumann

        ---

        "There's just so many extra children, we could just feed the
        children to these tigers. We don't need them, we're not doing
        anything with them.

        Tigers are noble and sleek; children are loud and messy."

        -- Neko Case

        Life is unfair. Kill yourself or get over it.
        -- Black Box Recorder
      Your message has been successfully submitted and would be delivered to recipients shortly.