Neil Mitchell Gluing things together with Haskell.

Slides:



Advertisements
Similar presentations
11-Jun-14 The assert statement. 2 About the assert statement The purpose of the assert statement is to give you a way to catch program errors early The.
Advertisements

Introducing JavaScript
Control-Flow Graphs & Dataflow Analysis CS153: Compilers Greg Morrisett.
Ruby (on Rails) CSE 190M, Spring 2009 Week 3. Web Programming in Ruby Ruby can be used to write dynamic web pages Similar to PHP, chunks of Ruby begins.
COS 461 Fall 1997 Where We Are u so far: networking u rest of semester: distributed computing –how to use networks to do interesting things –connection.
Shake Before Building Replacing Make with Haskell community.haskell.org/~ndm/shake Neil Mitchell.
18 June 2010 Upgrading Your Geant4 Release J. Perl 1 Upgrading Your Geant4 Release Joseph Perl, SLAC.
6 November 2009 Upgrading Your Geant4 Release J. Perl 1 Upgrading Your Geant4 Release Joseph Perl, SLAC Geant4 v9.2p02.
Chapter 3.1 Teams and Processes. 2 Programming Teams In the 1980s programmers developed the whole game (and did the art and sounds too!) Now programmers.
14 January 2011 Upgrading Your Geant4 Release J. Perl 1 Upgrading Your Geant4 Release Joseph Perl, SLAC.
CSE341: Programming Languages Lecture 11 Type Inference Dan Grossman Winter 2013.
G51FSE Version Control Naisan Benatar. Lecture 5 - Version Control 2 On today’s menu... The problems with lots of code and lots of people Version control.
#RefreshCache CI - Daily Builds w/Jenkins – an Open Source Continuous Integration Server Nick Airdo Community Developer Advocate Central Christian Church.
Version Control with git. Version Control Version control is a system that records changes to a file or set of files over time so that you can recall.
Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!
Using a Simple Python Script to Download Data Rob Letzler Goldman School of Public Policy July 2005.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
Erlware For Managing Distribution and Build Erlang User Conference 2007.
Map Reduce: Simplified Data Processing On Large Clusters Jeffery Dean and Sanjay Ghemawat (Google Inc.) OSDI 2004 (Operating Systems Design and Implementation)
CIS 338: Computer Languages & Visual Basic.NET
Visual Basic Advanced Programming.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
1 In the good old days... Years ago… the WWW was made up of (mostly) static documents. –Each URL corresponded to a single file stored on some hard disk.
1 Project Information and Acceptance Testing Integrating Your Code Final Code Submission Acceptance Testing Other Advice and Reminders.
The Structure of a C++ Program. Outline 1. Separate Compilation 2. The # Preprocessor 3. Declarations and Definitions 4. Organizing Decls & Defs into.
Software Development Software Testing. Testing Definitions There are many tests going under various names. The following is a general list to get a feel.
Building stuff with monadic dependencies + unchanging dependencies + polymorphic dependencies + abstraction Neil Mitchell
LECTURE 38: REFACTORING CSC 395 – Software Engineering.
1 Instant Data Warehouse Utilities Extended (Again!!) 14/7/ Today I am pleased to announce the publishing of some fantastic new functionality for.
SWEN 302: AGILE METHODS Roma Klapaukh & Alex Potanin.
Top Five Web Application Vulnerabilities Vebjørn Moen Selmersenteret/NoWires.org Norsk Kryptoseminar Trondheim
Copyright © 2015 – Curt Hill Version Control Systems Why use? What systems? What functions?
CINT C++ Interpreter update ROOT2001 at Fermi-Lab Masaharu Goto.
CS 4720 Dynamic Web Applications CS 4720 – Web & Mobile Systems.
Advanced Functional Programming Tim Sheard 1 Lecture 6 Functional Programming Tim Sheard & Mark Jones Monads & Interpreters.
What is a port The Ports Collection is essentially a set of Makefiles, patches, and description files placed in /usr/ports. The port includes instructions.
Presentation Name / 1 Visual C++ Builds and External Dependencies NAME.
Chapter 7 The Practices: dX. 2 Outline Iterative Development Iterative Development Planning Planning Organizing the Iterations into Management Phases.
1 Developing WBEM Clients Using Python Tim Potter Hewlett-Packard Company
1 Combining Events and Threads for Scalable Network Services Peng Li and Steve Zdancewic University of Pennsylvania PLDI 2007, San Diego.
Design - programming Cmpe 450 Fall Dynamic Analysis Software quality Design carefully from the start Simple and clean Fewer errors Finding errors.
1 MSTE Visual SourceSafe For more information, see:
UHCS 2005, slide 1 About Continuous Integration. UHCS 2005, slide 2 Why do you write Unit Test ? Improve quality/robustness of your code Quick feedback.
First Order Haskell Neil Mitchell York University λ.
REFERENCE: CHAPTER 1 High-level languages + Python.
Version Control and SVN ECE 297. Why Do We Need Version Control?
SPI NIGHTLIES Alex Hodgkins. SPI nightlies  Build and test various software projects each night  Provide a nightlies summary page that displays all.
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
Getting ready. Why C? Design Features – Efficiency (C programs tend to be compact and to run quickly.) – Portability (C programs written on one system.
FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University.
20 October 2005 LCG Generator Services monthly meeting, CERN Validation of GENSER & News on GENSER Alexander Toropin LCG Generator Services monthly meeting.
Perl Subroutines User Input Perl on linux Forks and Pipes.
C++ Functions A bit of review (things we’ve covered so far)
Lecture 1 Page 1 CS 111 Summer 2013 Important OS Properties For real operating systems built and used by real people Differs depending on who you are talking.
MAUS Status A. Dobbs CM43 29 th October Contents MAUS Overview Infrastructure Geometry and CDB Detector Updates CKOV EMR KL TOF Tracker Global Tracking.
Top 8 Best Programming Languages To Learn
CSE341: Programming Languages Lecture 11 Type Inference
Learning to Program D is for Digital.
PROGRAMMING IN HASKELL
X in [Integration, Delivery, Deployment]
Compiler Construction
CSE341: Programming Languages Lecture 11 Type Inference
PROGRAMMING IN HASKELL
CSE341: Programming Languages Lecture 11 Type Inference
JENKINS TIPS Ideas for making your life with Jenkins easier
Git CS Fall 2018.
CSE341: Programming Languages Lecture 11 Type Inference
Overview of My Experience With C++
CSE341: Programming Languages Lecture 11 Type Inference
CSE341: Programming Languages Lecture 11 Type Inference
Presentation transcript:

Neil Mitchell Gluing things together with Haskell

Code Elegantly designed Code Elegantly designed Release Thoroughly tested Release Thoroughly tested Build system Test harness Continuous integration Release bundling Installer generator Release distribution …

“A rats nest of Bash” Would your team write 10K lines of Bash? Lots of people write > 10K of Makefile – Standard Chartered, GHC developers

What to do? 1.Accept regular failures 2.Invest lots of time and money on an ongoing basis 3.Do it right (elegantly designed and thoroughly tested)

Shake Build system Shake Build system NSIS Installer generator NSIS Installer generator Bake Continuous integration Bake Continuous integration All open source Haskell libraries

Shake Build system Shake Build system

Shake for managers Build system - alternative to Make, Scons… Reliable and robust Powerful dependencies Fast to run xkcd.com

Shake for developers A Haskell library for writing build systems – Your code is in Haskell, but calling compilers etc Monadic dependencies (generated code) Polymorphic dependencies (not just files) Optimised and tested (faster than Ninja)

result.lst notes.txt talk.pdf pic.jpg result.tar notes.txt talk.pdf pic.jpg import Development.Shake import Development.Shake.FilePath main = shakeArgs shakeOptions $ do want ["result.tar"] "*.tar" *> \out -> do need [out - "lst"] contents "lst" need contents cmd "tar -cf" [out] contents An example

Monadic dependencies What does Foo.obj depend on (what does Foo.cpp #include) Applicative – Tell me the dependencies up front – Phases? Guess from Foo.xml? Monadic – New dependencies later – Generate Foo.cpp. Look at it. Foo.xml Foo.cpp generate cl Foo.obj

Polymorphic dependencies Way more than just files (but files are still the norm) Does a file exist (perfect for $INCLUDE paths) Contents of a directory (good for VS projects) Compiler/library versions – Upgrade a library, have the right things rebuild

Using Shake for our build system has been a very good decision so far, we've been able to minimise the time spent with platform-dependent build systems and IDEs and get to write Haskell code instead ;) Stefan Kersten, CTO Samplecount Cross-platform music stuff in C/Haskell Using Shake for > 2 years

At Standard Chartered > 10,000 lines Makefile became < 1,000 Shake Compiled more than 2x faster More malleable – no global phases A fantastic success – Our project keeps growing – Same structure as at the beginning – Monadic = more compositional

Stealing from Haskell Syntax, reasonable DSLs Some use of the type system (not heavy) Abstraction, functions/modules/packages Profiling the Haskell functions

Extra features HTML profile reports Very multithreaded Progress reporting Reports of live files Lint reports …

NSIS Installer generator NSIS Installer generator

NSIS – NullSoft Install System Originally the WinAmp installer (pre 2002) Generates small, fast Windows installer Lots of plugins

Quirky (understatement) Bad language – Scripted with a programming language – Twenty registers ($0, $R0), plus a stack, plus mem – Goto only, plus functions, no block if/for – Everything is a string (< 1Kb, or it segfaults) Bad structure – Nice user interface requires MUI2 – A set of preprocessor defines over NSIS

Solution: Haskell Define a DSL for writing NSIS libraries Generates NSIS code underneath Expression/Statement orientated – Very imperative

Comparison StrCmp $WINDIR $INSTDIR bad 0 StrCmp $SYSDIR $INSTDIR bad 0 Goto skip bad: MessageBox MBOK|MB_ICON_EXCLAMATION "Bad idea" skip: iff_ ("$INSTDIR" %== "$WINDIR" %|| "$INSTDIR" %== "$SYSDIR") $ alert "Bad idea" Vs

Comparison !Include MUI2.nsh Name "Example1" !insertmacro MUI_PAGE_DIRECTORY !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_LANGUAGE "English" Section "" _sec1 SetOutPath "$INSTDIR" File "Example1.hs" SectionEnd name "Example1" page Directory page InstFiles section "" [] $ do setOutPath "$INSTDIR" file [] "Example1.hs" Vs

Add types and structure data S = S Unique [NSIS] data Action a = Action (State S a) data Value ty = Value Val type Exp ty = Action (Value ty) -- ty is String, Int or Bool Monad Action Functor Action Applicative Action Enum (Exp Int) Eq (Exp a) Fractional (Exp Int) Integral (Exp Int) Num (Exp Int) Ord (Exp Int) Real (Exp Int) Show (Exp a)Monoid (Exp String) Bits (Exp Int) Typeable a => IsString (Exp a)

Reduce expressions iff_ :: Exp Bool -> Action () -> Action () iff_ test true = do thn <- newLabel end <- newLabel Value t <- test emit $ StrCmpS t (lit "") end thn label thn true label end

Optimise dullGoto :: [NSIS] -> [NSIS] dullGoto = transform f where f (Goto l1:Label l2:xs) | l1 == l2 = Label l2 : xs f x = x Goto foo foo:

Syntax, reasonable DSLs Phantom types to eliminate lots of errors Abstraction, build up in layers Standard compiler techniques Symbolic manipulation for optimisation – (which is pretty much totally unnecessary) Stealing from Haskell

Doesn’t define an installer, wraps an installer Polish off the rough edges, fix a few bugs Hide all the complexity Keep all the good stuff The Result

Bake Continuous integration Bake Continuous integration

Bake for managers Continuous integration – Travis, Jenkins… Designed for teams which are: – Large: ~5-50 people – Semi-trusted: Not always advance code review – Productive: Writing lots of code Never break the build

Bake for developers Master branch always works perfectly When code is ready, tell Bake Bake compiles it, runs the tests, merges it Bad code is rejected masterneil

Not enough time in the day 50 patches are promoted per day Compile & test = 10 hours (multithreaded) 20+ servers testing is infeasible – 2 might be reasonable, Windows & Linux Bake’s solution – Assume if p1+p2 pass the tests, that’s fine – If a test fails, then identify whether p1 or p2 fails

Configure in Haskell data Action = Compile | Test main = bake $ ovenGit repo "master" Nothing $ ovenTest (return [Compile,Test]) exec defaultOven exec Compile = run $ cmd "shake" exec Test = after [Compile] $ run $ cmd "test"

Users Client(s) Server * PrepareRun Query Merge HTTP Command line Dashboard Promote Request Reply * Clever stuff 90% string passing

String Passing the Haskell way data Stringy s = Stringy {stringyTo :: s -> String,stringyFrom :: String -> s,stringyPretty :: s -> String } stringyTo. stringyFrom == id stringyFrom. stringyTo == id check :: Stringy s -> Stringy s

Parameterisable and configurable – Parameterised over version control – Parameterised over tests Use types to safely pass different strings A bit of pure “clever” stuff in the middle Stealing from Haskell

Too early to say! Bake is only 6 weeks old Looks promising… The Result

Shake Build system Shake Build system NSIS Installer generator NSIS Installer generator Bake Continuous integration Bake Continuous integration Todo Lots more Todo Lots more