message: Reduce some duplication of pretty printing code
diff: @@ -398,60 +398,55 @@ impl ToDoc for Head {
  }
  }
  -impl ToDoc for raw::Definition {
  - fn to_doc(&self) -> StaticDoc {
  +fn pretty_definition(name: &str, ann: &impl ToDoc, term: &impl ToDoc) -> StaticDoc {
  sexpr(
  "define",
  - Doc::as_string(&self.name)
  + Doc::as_string(name)
  .append(Doc::space())
  - .append(self.ann.to_doc())
  + .append(ann.to_doc())
  .append(Doc::space())
  - .append(self.term.to_doc()),
  + .append(term.to_doc()),
  )
  }
  -}
  -impl ToDoc for raw::Module {
  - fn to_doc(&self) -> StaticDoc {
  +fn pretty_module<'a, Ds, D>(name: &str, definitions: Ds) -> StaticDoc
  +where
  + Ds: 'a + IntoIterator<Item = &'a D>,
  + D: 'a + ToDoc,
  +{
  sexpr(
  "module",
  - Doc::as_string(&self.name)
  + Doc::as_string(name)
  .append(Doc::newline())
  .append(Doc::intersperse(
  - self.definitions
  - .iter()
  + definitions
  + .into_iter()
  .map(|definition| definition.to_doc()),
  Doc::newline().append(Doc::newline()),
  )),
  )
  }
  +
  +impl ToDoc for raw::Definition {
  + fn to_doc(&self) -> StaticDoc {
  + pretty_definition(&self.name, &self.ann, &self.term)
  + }
  +}
  +
  +impl ToDoc for raw::Module {
  + fn to_doc(&self) -> StaticDoc {
  + pretty_module(&self.name, &self.definitions)
  + }
  }
  impl ToDoc for Definition {
  fn to_doc(&self) -> StaticDoc {
  - sexpr(
  - "define",
  - Doc::as_string(&self.name)
  - .append(Doc::space())
  - .append(self.ann.to_doc())
  - .append(Doc::space())
  - .append(self.term.to_doc()),
  - )
  + pretty_definition(&self.name, &self.ann, &self.term)
  }
  }
  impl ToDoc for Module {
  fn to_doc(&self) -> StaticDoc {
  - sexpr(
  - "module",
  - Doc::as_string(&self.name)
  - .append(Doc::newline())
  - .append(Doc::intersperse(
  - self.definitions
  - .iter()
  - .map(|definition| definition.to_doc()),
  - Doc::newline().append(Doc::newline()),
  - )),
  - )
  + pretty_module(&self.name, &self.definitions)
  }
  }
  