Notes and Todos
Small Knowledge Bases update.
Short update today — the definitions of note and todo types and their basic operations.
My intention is to represent arbitrary content as a note, and represent things to be done with todo. Notes are just an identifier, a title, and some content, while Todos also have a status and eventually relationships. I've left relationships between notes and todos for later. I'm not sure if I want them represented separately or as part of the structures.
Note
(** Note type and operations.
A note bundles an [Identifier.t] with a title and content.
*)
(** Abstract type of notes. *)
type t
(** [pp fmt t] prints the note [t] using the formatter [fmt]. *)
val pp : Format.formatter -> t -> unit
(** [show t] returns the same string that {!pp} would print. *)
val show : t -> string
(** [make identifier title content] constructs a note after validating inputs.
- [title] must be non-empty and at most 100 characters.
- [content] must be non-empty and at most 10000 characters.
@raise Invalid_argument if validation fails. *)
val make : Identifier.t -> string -> string -> t
(** [id t] returns the note identifier. *)
val id : t -> Identifier.t
(** [title t] returns the title of the note. *)
val title : t -> string
(** [content t] returns the content of the note. *)
val content : t -> string
Todo
(** Todo type and operations.
A todo pairs a note with a workflow status. The status can be [Open],
[In_Progress], or [Done].
*)
(** Status of a todo item. *)
type status = Open | In_Progress | Done
(** Abstract type of todos. *)
type t
(** [pp fmt t] prints the todo [t] using the formatter [fmt]. *)
val pp : Format.formatter -> t -> unit
(** [show t] returns the same string that {!pp} would print. *)
val show : t -> string
(** [status_to_string status] returns the string representation of the status. *)
val status_to_string : status -> string
(** [status_from_string s] parses [s] as a status.
Accepts the strings ["open"], ["in-progress"], and ["done"].
@raise Invalid_argument if parsing fails. *)
val status_from_string : string -> status
(** [make note status] constructs a todo from [note] and [status]. *)
val make : Note.t -> status -> t
(** [note t] returns the note component. *)
val note : t -> Note.t
(** [status t] returns the status component. *)
val status : t -> status
(** [id t] returns the identifier of the note within the todo. *)
val id : t -> Identifier.t
Retro
The code is here. Not much to like or dislike. Introducing ppx_deriving was easy, as was using it. The expect tests continue to be nice.