lean4-htt/library/init/data/char/basic.lean
Leonardo de Moura a0a8103804 chore(frontends/lean): go back to 'c' as notation for characters
This suggestion has been discussed at Slack.
We have decided to use #"c" as notation because we wanted to allow `'`
in the beginning of identifiers like in SML and F*. In particular,
we wanted to allow users to use 'a 'b 'c for naming type parameters
like in SML. However, nobody used this notation. In the Lean standard
library, we are using greek letters for naming type parameters.
So, there is no real motivation for the ugly #"c" syntax.
2017-05-02 13:00:51 -07:00

35 lines
778 B
Text

/-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
-/
prelude
import init.data.fin.basic
open nat
def char_sz : nat := succ 255
def char := fin char_sz
instance : has_sizeof char :=
⟨fin.sizeof _⟩
namespace char
/- We cannot use tactic dec_trivial here because the tactic framework has not been defined yet. -/
lemma zero_lt_char_sz : 0 < char_sz :=
zero_lt_succ _
@[pattern] def of_nat (n : nat) : char :=
if h : n < char_sz then fin.mk n h else fin.mk 0 zero_lt_char_sz
def to_nat (c : char) : nat :=
fin.val c
end char
instance : decidable_eq char :=
have decidable_eq (fin char_sz), from fin.decidable_eq _,
this
instance : inhabited char :=
⟨'A'⟩