Skip to content

Commit bd1caa9

Browse files
author
Gregory Malecha
committed
a simple example for printing.
1 parent ab28e47 commit bd1caa9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

examples/Printing.v

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Require Import Coq.Strings.String.
2+
Require Import ExtLib.Structures.MonadWriter.
3+
Require Import ExtLib.Data.Monads.WriterMonad.
4+
Require Import ExtLib.Data.Monads.IdentityMonad.
5+
Require Import ExtLib.Programming.Show.
6+
7+
Definition PrinterMonad : Type -> Type :=
8+
writerT (@show_mon _ ShowScheme_string_compose) ident.
9+
10+
Definition print {T : Type} {ST : Show T} (val : T) : PrinterMonad unit :=
11+
@MonadWriter.tell _ (@show_mon _ ShowScheme_string_compose) _ _
12+
(@show _ ST val _ show_inj (@show_mon _ ShowScheme_string_compose)).
13+
14+
Definition runPrinter {T : Type} (c : PrinterMonad T) : T * string :=
15+
let '(val,str) := unIdent (runWriterT c) in
16+
(val, str ""%string).
17+
18+
19+
Eval compute in runPrinter (Monad.bind (print 1) (fun _ => print 2)).

0 commit comments

Comments
 (0)