misusing the type system for
play

Misusing the Type System for & Ian Dees @undees PNSQC 2015 - PowerPoint PPT Presentation

Misusing the Type System for & Ian Dees @undees PNSQC 2015 Brewing for Maintainability Our contaminants: s k a e l y r o m Failing e M regression tests C r a s h e s Poor repeatability Data corruption s e h


  1. > rewrite (plusSuccRightSucc y x) ---------- Other goals: ---------- { hole 3 } { hole 2 } { hole 1 } { hole 0 } ---------- Assumptions: ---------- x : Nat y : Nat hypothesis : plus x y = plus y x ---------- Goal: ---------- { hole 4 }: S (plus x y) = S (plus y x)

  2. > rewrite hypothesis ---------- Other goals: ---------- { hole 4 } { hole 3 } { hole 2 } { hole 1 } { hole 0 } ---------- Assumptions: ---------- x : Nat y : Nat hypothesis : plus x y = plus y x ---------- Goal: ---------- { hole 5 }: S (plus x y) = S (plus x y)

  3. > rewrite hypothesis ---------- Other goals: ---------- { hole 4 } { hole 3 } { hole 2 } { hole 1 } { hole 0 } ---------- Assumptions: ---------- x : Nat y : Nat hypothesis : plus x y = plus y x ---------- Goal: ---------- { hole 5 }: S (plus x y) = S (plus x y)

  4. > trivial inductive: No more goals. > qed Proof completed! Math.inductive = proof intros rewrite (plusSuccRightSucc y x) rewrite hypothesis trivial

  5. 3. Applying the ideas 
 in the real world

  6. Mission: 
 Edit audio clips

  7. class Audio { public: };

  8. class Audio { public: size_t count() const; };

  9. class Audio { public: size_t count() const; int16_t operator[](size_t i) const; int16_t& operator[](size_t i); };

  10. class Audio { public: size_t count() const; int16_t operator[](size_t i) const; int16_t& operator[](size_t i); double timeAtZero() const; double sampleRate() const; };

  11. class Audio { public: size_t count() const; int16_t operator[](size_t i) const; int16_t& operator[](size_t i); double timeAtZero() const; double sampleRate() const; double verticalScale() const; };

  12. Audio audio; double time = 0.5; size_t index = (time - audio.timeAtZero()) / audio.sampleRate();

  13. Audio audio; double time = 0.5; size_t index = (time - audio.timeAtZero()) / audio.sampleRate(); int16_t value = audio[index]; double level = static_cast<double>(value) * audio.verticalScale();

  14. class Audio { public: size_t count() const; int16_t operator[](size_t i) const; int16_t& operator[](size_t i); double timeAtZero() const; double sampleRate() const; double verticalScale() const; };

  15. class Audio { public: size_t count() const; int16_t operator[](size_t i) const; int16_t& operator[](size_t i); double timeAtZero() const; double sampleRate() const; double verticalScale() const; std::string fileName() const; std::string comments() const; bool isStereo() const; void loadFromFile(const std::string& filename); void saveToFile(const std::string& filename); };

  16. What is an audio clip?

Recommend


More recommend