chore(library/system): enforce Lean naming conventions IO ==> io

This commit is contained in:
Leonardo de Moura 2016-11-17 11:12:46 -08:00
parent 85a532b5af
commit e16e9880f7
19 changed files with 71 additions and 71 deletions

View file

@ -3,4 +3,4 @@ Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad
-/
import system.IO
import system.io

View file

@ -1,25 +0,0 @@
/-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Luke Nelson, Jared Roesch and Leonardo de Moura
-/
constant {u} IO : Type u → Type u
constant functorIO : functor IO
constant monadIO : monad IO
attribute [instance] functorIO monadIO
constant put_str : string → IO unit
constant put_nat : nat → IO unit
constant get_line : IO string
meta constant format.print_using : format → options → IO unit
meta definition format.print (fmt : format) : IO unit :=
format.print_using fmt options.mk
meta definition pp_using {A : Type} [has_to_format A] (a : A) (o : options) : IO unit :=
format.print_using (to_fmt a) o
meta definition pp {A : Type} [has_to_format A] (a : A) : IO unit :=
format.print (to_fmt a)

25
library/system/io.lean Normal file
View file

@ -0,0 +1,25 @@
/-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Luke Nelson, Jared Roesch and Leonardo de Moura
-/
constant {u} io : Type u → Type u
constant io.functor : functor io
constant io.monad : monad io
attribute [instance] io.functor io.monad
constant put_str : string → io unit
constant put_nat : nat → io unit
constant get_line : io string
meta constant format.print_using : format → options → io unit
meta definition format.print (fmt : format) : io unit :=
format.print_using fmt options.mk
meta definition pp_using {A : Type} [has_to_format A] (a : A) (o : options) : io unit :=
format.print_using (to_fmt a) o
meta definition pp {A : Type} [has_to_format A] (a : A) : io unit :=
format.print (to_fmt a)

View file

@ -439,9 +439,9 @@ static environment vm_eval_cmd(parser & p) {
type_context tc(p.env(), transparency_mode::All);
expr type0 = tc.infer(e);
expr type = tc.whnf(type0);
bool is_IO = is_constant(get_app_fn(type), get_IO_name());
bool is_io = is_constant(get_app_fn(type), get_io_name());
bool is_string = false;
if (!is_IO) {
if (!is_io) {
/* Check if resultant type has an instance of has_to_string */
level lvl = sort_level(tc.whnf(tc.infer(type)));
expr has_to_string_type = mk_app(mk_constant(get_has_to_string_name(), {lvl}), type0);
@ -457,7 +457,7 @@ static environment vm_eval_cmd(parser & p) {
environment new_env = compile_expr(p.env(), main, ls, type, e, pos);
vm_state s(new_env, p.get_options());
optional<vm_obj> initial_state;
if (is_IO) initial_state = mk_vm_simple(0);
if (is_io) initial_state = mk_vm_simple(0);
auto out = p.mk_message(pos, INFORMATION);
out.set_caption("vm_eval result");
vm_state::profiler prof(s, p.get_options());
@ -468,7 +468,7 @@ static environment vm_eval_cmd(parser & p) {
} else {
vm_eval_core(s, main, initial_state);
}
if (is_IO) {
if (is_io) {
// do not print anything
} else if (is_string) {
vm_obj r = s.get(0);

View file

@ -302,7 +302,7 @@ class erase_irrelevant_fn : public compiler_step_visitor {
}
static bool is_builtin_state_monad(expr const & e) {
return is_constant(e, get_monadIO_name());
return is_constant(e, get_io_monad_name());
}
expr visit_monad_bind(expr const & e, buffer<expr> const & args) {

View file

@ -72,7 +72,6 @@ name const * g_eq_rec_heq = nullptr;
name const * g_exists_elim = nullptr;
name const * g_format = nullptr;
name const * g_functor = nullptr;
name const * g_functorIO = nullptr;
name const * g_false = nullptr;
name const * g_false_of_true_iff_false = nullptr;
name const * g_false_rec = nullptr;
@ -142,7 +141,9 @@ name const * g_int_has_lt = nullptr;
name const * g_int_has_neg = nullptr;
name const * g_int_has_mod = nullptr;
name const * g_int_decidable_linear_ordered_comm_group = nullptr;
name const * g_IO = nullptr;
name const * g_io = nullptr;
name const * g_io_functor = nullptr;
name const * g_io_monad = nullptr;
name const * g_is_associative = nullptr;
name const * g_is_associative_op_assoc = nullptr;
name const * g_is_int = nullptr;
@ -174,7 +175,6 @@ name const * g_monad_map = nullptr;
name const * g_monad_bind = nullptr;
name const * g_monad_ret = nullptr;
name const * g_monad_and_then = nullptr;
name const * g_monadIO = nullptr;
name const * g_monoid = nullptr;
name const * g_mul = nullptr;
name const * g_mul_one = nullptr;
@ -464,7 +464,6 @@ void initialize_constants() {
g_exists_elim = new name{"exists", "elim"};
g_format = new name{"format"};
g_functor = new name{"functor"};
g_functorIO = new name{"functorIO"};
g_false = new name{"false"};
g_false_of_true_iff_false = new name{"false_of_true_iff_false"};
g_false_rec = new name{"false", "rec"};
@ -534,7 +533,9 @@ void initialize_constants() {
g_int_has_neg = new name{"int", "has_neg"};
g_int_has_mod = new name{"int", "has_mod"};
g_int_decidable_linear_ordered_comm_group = new name{"int_decidable_linear_ordered_comm_group"};
g_IO = new name{"IO"};
g_io = new name{"io"};
g_io_functor = new name{"io", "functor"};
g_io_monad = new name{"io", "monad"};
g_is_associative = new name{"is_associative"};
g_is_associative_op_assoc = new name{"is_associative", "op_assoc"};
g_is_int = new name{"is_int"};
@ -566,7 +567,6 @@ void initialize_constants() {
g_monad_bind = new name{"monad", "bind"};
g_monad_ret = new name{"monad", "ret"};
g_monad_and_then = new name{"monad", "and_then"};
g_monadIO = new name{"monadIO"};
g_monoid = new name{"monoid"};
g_mul = new name{"mul"};
g_mul_one = new name{"mul_one"};
@ -857,7 +857,6 @@ void finalize_constants() {
delete g_exists_elim;
delete g_format;
delete g_functor;
delete g_functorIO;
delete g_false;
delete g_false_of_true_iff_false;
delete g_false_rec;
@ -927,7 +926,9 @@ void finalize_constants() {
delete g_int_has_neg;
delete g_int_has_mod;
delete g_int_decidable_linear_ordered_comm_group;
delete g_IO;
delete g_io;
delete g_io_functor;
delete g_io_monad;
delete g_is_associative;
delete g_is_associative_op_assoc;
delete g_is_int;
@ -959,7 +960,6 @@ void finalize_constants() {
delete g_monad_bind;
delete g_monad_ret;
delete g_monad_and_then;
delete g_monadIO;
delete g_monoid;
delete g_mul;
delete g_mul_one;
@ -1249,7 +1249,6 @@ name const & get_eq_rec_heq_name() { return *g_eq_rec_heq; }
name const & get_exists_elim_name() { return *g_exists_elim; }
name const & get_format_name() { return *g_format; }
name const & get_functor_name() { return *g_functor; }
name const & get_functorIO_name() { return *g_functorIO; }
name const & get_false_name() { return *g_false; }
name const & get_false_of_true_iff_false_name() { return *g_false_of_true_iff_false; }
name const & get_false_rec_name() { return *g_false_rec; }
@ -1319,7 +1318,9 @@ name const & get_int_has_lt_name() { return *g_int_has_lt; }
name const & get_int_has_neg_name() { return *g_int_has_neg; }
name const & get_int_has_mod_name() { return *g_int_has_mod; }
name const & get_int_decidable_linear_ordered_comm_group_name() { return *g_int_decidable_linear_ordered_comm_group; }
name const & get_IO_name() { return *g_IO; }
name const & get_io_name() { return *g_io; }
name const & get_io_functor_name() { return *g_io_functor; }
name const & get_io_monad_name() { return *g_io_monad; }
name const & get_is_associative_name() { return *g_is_associative; }
name const & get_is_associative_op_assoc_name() { return *g_is_associative_op_assoc; }
name const & get_is_int_name() { return *g_is_int; }
@ -1351,7 +1352,6 @@ name const & get_monad_map_name() { return *g_monad_map; }
name const & get_monad_bind_name() { return *g_monad_bind; }
name const & get_monad_ret_name() { return *g_monad_ret; }
name const & get_monad_and_then_name() { return *g_monad_and_then; }
name const & get_monadIO_name() { return *g_monadIO; }
name const & get_monoid_name() { return *g_monoid; }
name const & get_mul_name() { return *g_mul; }
name const & get_mul_one_name() { return *g_mul_one; }

View file

@ -74,7 +74,6 @@ name const & get_eq_rec_heq_name();
name const & get_exists_elim_name();
name const & get_format_name();
name const & get_functor_name();
name const & get_functorIO_name();
name const & get_false_name();
name const & get_false_of_true_iff_false_name();
name const & get_false_rec_name();
@ -144,7 +143,9 @@ name const & get_int_has_lt_name();
name const & get_int_has_neg_name();
name const & get_int_has_mod_name();
name const & get_int_decidable_linear_ordered_comm_group_name();
name const & get_IO_name();
name const & get_io_name();
name const & get_io_functor_name();
name const & get_io_monad_name();
name const & get_is_associative_name();
name const & get_is_associative_op_assoc_name();
name const & get_is_int_name();
@ -176,7 +177,6 @@ name const & get_monad_map_name();
name const & get_monad_bind_name();
name const & get_monad_ret_name();
name const & get_monad_and_then_name();
name const & get_monadIO_name();
name const & get_monoid_name();
name const & get_mul_name();
name const & get_mul_one_name();

View file

@ -67,7 +67,6 @@ eq_rec_heq
exists.elim
format
functor
functorIO
false
false_of_true_iff_false
false.rec
@ -137,7 +136,9 @@ int.has_lt
int.has_neg
int.has_mod
int_decidable_linear_ordered_comm_group
IO
io
io.functor
io.monad
is_associative
is_associative.op_assoc
is_int
@ -169,7 +170,6 @@ monad.map
monad.bind
monad.ret
monad.and_then
monadIO
monoid
mul
mul_one

View file

@ -10,9 +10,9 @@ Author: Leonardo de Moura
namespace lean {
bool is_system_builtin(name const & n) {
return
n == get_IO_name() ||
n == get_functorIO_name() ||
n == get_monadIO_name() ||
n == get_io_name() ||
n == get_io_functor_name() ||
n == get_io_monad_name() ||
n == get_put_str_name() ||
n == get_put_nat_name() ||
n == get_get_line_name();

View file

@ -1,4 +1,4 @@
import system.IO
import system.io
check 'a'

View file

@ -1,9 +1,9 @@
import system.IO
import system.io
open list
-- set_option pp.all true
definition main : IO unit :=
definition main : io unit :=
do l₁ ← get_line,
l₂ ← get_line,
put_str (l₂ ++ l₁)
@ -15,7 +15,7 @@ vm_eval put_str "hello\n"
print "************************"
definition aux (n : nat) : IO unit :=
definition aux (n : nat) : io unit :=
do put_str "========\nvalue: ",
put_nat n,
put_str "\n========\n"
@ -24,7 +24,7 @@ vm_eval aux 20
print "************************"
definition repeat : nat → (nat → IO unit) → IO unit
definition repeat : nat → (nat → io unit) → io unit
| 0 a := return ()
| (n+1) a := do a n, repeat n a
@ -32,7 +32,7 @@ vm_eval repeat 10 aux
print "************************"
definition execute : list (IO unit) → IO unit
definition execute : list (io unit) → io unit
| [] := return ()
| (x::xs) := do x, execute xs

View file

@ -1,4 +1,4 @@
import system.IO
import system.io
open list
/- B and unit must be in the same universe
@ -6,7 +6,7 @@ open list
since unit is at Type₁
-/
definition foreach {A : Type} {B : Type} : list A → (A → IO B) → IO poly_unit
definition foreach {A : Type} {B : Type} : list A → (A → io B) → io poly_unit
| [] f := return poly_unit.star
| (x::xs) f := do f x, foreach xs f

View file

@ -1,6 +1,6 @@
import system.IO
import system.io
definition main : IO unit :=
definition main : io unit :=
do { l ← get_line,
if l = "hello" then
put_str "you have typed hello\n"

View file

@ -1,8 +1,8 @@
import system.IO
import system.io
set_option trace.compiler.code_gen true
definition main : IO unit :=
definition main : io unit :=
do { n ← return (10:nat),
if n = (11:nat) then
put_nat 1

View file

@ -1,4 +1,4 @@
import system.IO
import system.io
open list
vm_eval pp ([["aaa", "bbb", "ccc", "dddd", "eeeeee", "ffffff"], ["aaa", "bbb", "ccc", "dddd", "eeeeee", "ffffff"],

View file

@ -1,9 +1,9 @@
import system.IO
import system.io
meta definition foo : nat → nat
| a := nat.cases_on a 1 (λ n, foo n + 2)
vm_eval (foo 10)
meta definition loop : nat → IO unit
meta definition loop : nat → io unit
| a := do put_str ">> ", put_nat a, put_str "\n", loop (a+1)

View file

@ -1,4 +1,4 @@
import system.IO
import system.io
vm_eval do pp (level.max (level.succ level.zero) (level.param `foo)), put_str "\n"

View file

@ -1,4 +1,4 @@
import system.IO
import system.io
section
open nat_map

View file

@ -1,6 +1,6 @@
import system.IO
import system.io
definition when (b : bool) (a : IO unit) : IO unit :=
definition when (b : bool) (a : io unit) : io unit :=
if b = tt then a else return ()
vm_eval when tt (put_str "hello\n")