Data Tree a = E | N (Tree a) a (Tree a) deriving (Show) task :: Integer -> [Tree Integer] -> Tree b -> (Integer,[Tree Integer],[Tree b],Tree Integer) task.

Slides:



Advertisements
Similar presentations
Variable types We have already encountered the idea of a variable type. It is also possible to think about variables in terms of their kind, namely: 1)
Advertisements

GHood Visualising Observations of Haskell Program Runs Claus Reinke Computing Lab, University of Kent at Canterbury.
Java Programming, 3e Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
4 July 2005 overview Traineeship: Mapping of data structures in multiprocessor systems Nick de Koning
COMP171 Data Structure & Algorithm Tutorial 1 TA: M.Y.Chan.
Representing programs Goals. Representing programs Primary goals –analysis is easy and effective just a few cases to handle directly link related things.
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
Chapter 11 Exception Handling and Event Handling.
Scripting Languages For Virtual Worlds. Outline Necessary Features Classes, Prototypes, and Mixins Static vs. Dynamic Typing Concurrency Versioning Distribution.
©2004 Brooks/Cole Chapter 1: Getting Started Sections Covered: 1.1Introduction to Programming 1.2Constructing a Java Program 1.3The print() and println()
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Introduction to a Programming Environment
Type Inference: CIS Seminar, 11/3/2009 Type inference: Inside the Type Checker. A presentation by: Daniel Tuck.
Course Instructor: Aisha Azeem
Programming. Software is made by programmers Computers need all kinds of software, from operating systems to applications People learn how to tell the.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Programming Paradigms Imperative programming Functional programming Logic programming Event-driven programming Object-oriented programming A programming.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
The Project AH Computing. Functional Requirements  What the product must do!  Examples attractive welcome screen all options available as clickable.
Starting Chapter 4 Starting. 1 Course Outline* Covered in first half until Dr. Li takes over. JAVA and OO: Review what is Object Oriented Programming.
Chapter 7 Designing Classes. Class Design When we are developing a piece of software, we want to design the software We don’t want to just sit down and.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
M1G Introduction to Programming 2 4. Enhancing a class:Room.
COMPUTER PROGRAMMING Source: Computing Concepts (the I-series) by Haag, Cummings, and Rhea, McGraw-Hill/Irwin, 2002.
CSC 142 O 1 CSC 142 Java More About Inheritance & Interfaces [Reading: chapter 13]
Invitation to Computer Science, Java Version, Second Edition.
CMSC 202 Exceptions. Aug 7, Error Handling In the ideal world, all errors would occur when your code is compiled. That won’t happen. Errors which.
CSE 425: Data Types II Survey of Common Types I Records –E.g., structs in C++ –If elements are named, a record is projected into its fields (e.g., via.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Building Tools by Model Transformations in Eclipse Oskars Vilitis, Audris Kalnins, Edgars Celms, Elina Kalnina, Agris Sostaks, Janis Barzdins Institute.
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
SE: CHAPTER 7 Writing The Program
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 15: More-Advanced Concepts.
Chapter 7 File I/O 1. File, Record & Field 2 The file is just a chunk of disk space set aside for data and given a name. The computer has no idea what.
Guide to Programming with Python Chapter One Getting Started: The Game Over Program.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Copyright © Curt Hill Generic Classes Template Classes or Container Classes.
Data Structures R e c u r s i o n. Recursive Thinking Recursion is a problem-solving approach that can be used to generate simple solutions to certain.
The Software Development Process
Instructions. Portability In addition to making hardware backward compatible, we have also made software portable. In describing software, “portable”
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Java Programming, 2E Introductory Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
M1G Introduction to Programming 2 5. Completing the program.
 Control Flow statements ◦ Selection statements ◦ Iteration statements ◦ Jump statements.
More about Java Classes Writing your own Java Classes More about constructors and creating objects.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
Source Level Debugging of Parallel Programs Roland Wismüller LRR-TUM, TU München Germany.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
OOP Basics Classes & Methods (c) IDMS/SQL News
Program Design. Simple Program Design, Fourth Edition Chapter 1 2 Objectives In this chapter you will be able to: Describe the steps in the program development.
LLVM IR, File - Praakrit Pradhan. Overview The LLVM bitcode has essentially two things A bitstream container format Encoding of LLVM IR.
GUI Design and Coding PPT By :Dr. R. Mall.
Unified Modeling Language
CS 326 Programming Languages, Concepts and Implementation
Structural style Modular design and hierarchy Part 1
UNIT - V STORED PROCEDURE.
Debugging Haskell by Observing Intermediate Data Structures
Phil Tayco Slide version 1.0 Created Oct 2, 2017
Unit# 9: Computer Program Development
Objects First with Java
Type & Typeclass Syntax in function
Programming.
A programming language
Names and Binding In Text: Chapter 5.
Presentation transcript:

data Tree a = E | N (Tree a) a (Tree a) deriving (Show) task :: Integer -> [Tree Integer] -> Tree b -> (Integer,[Tree Integer],[Tree b],Tree Integer) task n ~rs E = (n,rs,[],E) task n ~(r':l':rs) (N l x r) = (n+1,rs,[l,r],N l' n r') taskM :: Integer -> [Tree b] -> [Tree Integer] taskM n [] = [] taskM n (t:ts) = rs'++[t'] where (n',rs',tp',t') = task n ts' t ts' = taskM n' (ts++tp') bfnum :: Tree a -> Tree Integer bfnum t = head $ taskM 1 [t] data Tree a = E | N (Tree a) a (Tree a) deriving (Show) task n ~rs E = (n,rs,[],E) task n ~(r':l':rs) (N l x r) = (n+1,rs,[l,r],N l' n r') taskM n [] = [] taskM n (t:ts) = rs'++[t'] where (n',rs',tp',t') = task n ts' t ts' = taskM n' (ts++tp') bfnum t = head $ taskM 1 [t] GHood Visualising Observations of Haskell Program Runs Claus Reinke Computing Lab, University of Kent at Canterbury data Tree a = E | N (Tree a) a (Tree a) deriving (Show).. code as before.. someTree = N (N (N E 0 E) 1 (N E 0 E)) 2 (N (N E 0 E) 1 (N E 0 E)) main = print $ bfnum someTree {- compare input tree and program output: N (N (N E 0 E) 1 (N E 0 E)) 2 (N (N E 0 E) 1 (N E 0 E)) N (N (N E 4 E) 2 (N E 5 E)) 1 (N (N E 6 E) 3 (N E 7 E)) -}

GHood Visualising Observations of Haskell Program Runs Claus Reinke Computing Lab, University of Kent at Canterbury import Observe data Tree a = E | N (Tree a) a (Tree a) deriving (Show) instance Observable a => Observable (Tree a) where observer E = send "E" (return E) observer (N l x r) = send "N" (return N << l << x << r).. code as before.. main = printO $ observe “after” $ bfnum $ observe “before” $ someTree data Tree a = E | N (Tree a) a (Tree a) deriving (Show).. code as before.. someTree = N (N (N E 0 E) 1 (N E 0 E)) 2 (N (N E 0 E) 1 (N E 0 E)) main = print $ bfnum someTree -- setting up a sensible testbed isn‘t always that easy; -- we might want to test parts of a program, but in their -- original context!

Declarative versus imperative style declarative programs tend to describe the “what?” of computations, leaving the “how?” implicit imperative programs tend to prescribe the “how?” of computations, leaving the “what?” implicit functional programs tend to emphasise a descriptive style while also indicating possible ways of computing this is a useful compromise, supported by experience: –1. get it right (only if necessary: 2. make it efficient) –surprisingly often, compilers can do a good job of 2. –sometimes, they need a little help..

The implicit “how” Functional programmers have tried to leave operational aspects to “clever” compilers, as far as possible.. compilers have become quite good, but –they rarely change your algorithms/data structures –they can’t guess what you want (value of resources?) most operational aspects are still handled implicitly: 0. programs describe algorithms 1. compilers “derive” code directly from the algorithms in your programs, using some operational semantics 2. compilers “optimise” within algorithms/data structures 3. low-level profilers help you to see the resource usage 4. you change your program and try again..  unknowns in 1&2, declarativeness compromised by 4!

The “what” of “how” - part I (specification) Programs = declarations + operational aspects operational aspects implicit  compiler chooses defaults –one set of defaults is not always adequate –should we really try to guess those defaults?  options & pragmas, but do they need to be imperative? (who knows appendix E.3 to the Haskell report?) –should we really change the declarations to get an indirect handle on the operational aspects? improved declarative (?) means to describe operational aspects of functional programs seem to be called for, as well as means to instantiate declarative programs with some specific operational properties (aspect-oriented programming has some ideas on the latter)aspect-oriented programming

The “what” of “how” – part II (understanding) Programs = declarations + operational aspects (similar to logic + proof theory) we need a better understanding of program behaviour –what are operational aspects? (space/time use during compilation/execution, strictness, dependencies,..) –can they be isolated from declarative aspects? –high-level operational semantics would be useful –the problems are dynamic in nature, so high-level animations of program behaviour would be a nice way to gain insights –..  lots of other interesting issues, but this talk is only about the visualisation of program behaviour

Looking glass, moving over reduction sequence redexreduct ([1+1]++[2*3,3!])!!1  ((1+1):([]++[2*3,3!]))!!1  ([]++[2*3,3!])!!(1-1)  ([]++[2*3,3!])!!0  [2*3,3!]!!0  2*3  6 Program behaviour: flow versus rewriting : *! [] + : : ++ !! 1 operand operator result  reduction  datademand  Probe, showing data flowing through different views, leading to tools focussing of different aspects

From reduction traces to flow observations, in a few easy steps All Haskell implementations support the non-standard trace: String -> a -> a -- output first parameter, return second parameter -- a labelled polymorphic identity function? simple idea of tracing reduction sequences: –use trace to tag redices with String labels –runtime system outputs label when redex is reduced –the resulting trace of redex labels gives an indication of what reduction sequence was followed

Some problems with trace P1: where to get sensible trace labels from? –compute label from labelled redex (and its context) –extra code to embed useful information into trace labels –we’re getting closer to debugging by print statements.. P2: non-strict evaluation of functional programs is quite unlike sequential, in-order execution of imperative code. Program traces can be very difficult to read.. (e.g., evaluation dependencies can lead to nested labels!) P3: replacing constant String labels by String -valued expressions could change the program under inspection! As a typical example, (showTrace s) changes strictness: showTrace :: Show a => String ->a -> a showTrace s a = trace (s++(show a)) a

Interlude: Side-effecting pseudo-functions for i/o, again? P2 is just an instance of the general conflict between i/o by side-effect, as in trace, and non-strict evaluation order. The general solutions make the sequencing of i/o operations explicit as part of program results. We can’t use any of the general solutions here: we want to change the program under inspection as little as possible! i/o and tracing look similar but are actually quite different: –functional i/o tries to add i/o to functional programs –tracing tries to add i/o to functional language implementations

From trace to observe (outline) P1: where to get sensible labels from? –provide the extra code for gathering information about parameters in a library, returning labels to a tag-role –use type classes to provide versions of generic code P2: confusing output in evaluation order –don’t output observations in evaluation order –use labels to group related observations together P3: danger of changing program properties –factoring observation code into a library localises possible problems and allows to reuse code that works –mere inspection of data can introduce new demands for evaluation, so be careful not to inspect anything unless the original program inspects it as well!

Behind the scenes unsafePerformIO :: IO a -> a Usually seen as side-effecting pseudo function for dirty work that may need to be done in libraries: use normal IO, then „pretend that nothing has happened“ (prefix unsafe indicates proof obligation) Just what we need for tracing, observing, and debugging? –can implement trace: trace l a = unsafePerformIO (putStr l >> return a) –can also maintain state of unique label supply, easing construction of partial data structures from observations –could even support user interaction Can also be seen as an extension hook in the evaluation mechanism, programmable in Haskell itself!

Observing lists (pseudo-code) observe l p [] [] l p :“[]” observe l p (h:t) (observe l 1 h:observe l 2 t) l p :“_ 1 :_ 2 ” Force evaluation to whnf, but only if context demands it anyway! Don’t observe sub-structures immediately, but make sure we hear about it if they ever get evaluated! Observation pool contains three kinds of information: what? where? when?

Observations Observations form labelled trees, built up incrementally At each step, observation trees represent partial knowledge of data structures passing through observation points Life-time of a node: thunk as yet unknown part, not yet under inspection thunk as yet unknown part, currently under inspection partially known structure, as yet unknown parts c thunk

Hood/Ghood - variations of a theme The vanilla version of Hood consists of the library Observe –observations are collected, grouped and pretty-printed –very useful for probing data-flow in your programs, but it only uses the “what” and “where” information Hood in nhc98 comes with a textual observation browser –all advantages of vanilla version, plus use of “when” information for animation (of structure refinement) –doesn’t work so well when observing bigger structures: lots of scrolling, no scaling, no survey view –text wouldn’t be visible in smaller scale, and structure gets lost due the form of pretty-printing used Ghood is a graphical observation browser..

GHood demos GHood as a stand-alone browser, started by a Haskell evaluator or from the commandlineGHood as a stand-alone browser GHood as an applet in webpagesGHood as an applet Current development of GHood focusses on –How to capture dynamic info in static snapshots? –Visualising evaluation dependencies –Replacing scrollbars and scaling-slider with more suitable forms of control (scrollbox, auto-scaling) –Upgrading to structure-preserving tree layout algorithm –..lots of other open roads to follow.. Some ideas that don‘t quite work: fading colours, scrollbars, life-time maps (visual or textual),..

Preliminary conclusions Animating Hood observations using a Java-based browser allows for portable visualisation of program behaviour, even in online documentation of functional programs! [but using Java isn‘t problem-free] Animation exploits the information represented by the relative ordering of observations, enabling high-level observations of dynamic program properties. Graphical visualisation offers the usual advantages of scale over textual methods (when labels are no longer readable, structure should be recognizable after layout). [but standard user interface issues come into play] User feedback has been encouragingly positive so far. Please try it yourselves: