Std. Literal
(Cure Standard Library v0.37.2)
View Source
User-defined contextual integer literals.
A bare numeral still defaults to Int. In a checking position the
elaborator asks these interfaces to construct the expected type. The
result wrapper keeps conversion total: finite domains such as Bounded(n)
reject an out-of-range literal during compilation rather than trapping or
silently wrapping at runtime.
Examples
use Std.Literal
from_atom_literal(AtomLiteral{value: :ok}) # => LiteralValue(:ok)
Summary
Types
Literal descriptors separate authored syntax from its eventual target type. Numeric spelling is normalized (digit separators are removed) but remains exact; decoded string/character/atom values are carried directly.
Functions
Primitive Float conversions are explicitly lossy: choosing Float is the user's request to round an exact literal to IEEE-754. Decimal and custom targets never pass through these helpers.
Types
struct AtomLiteral
?
struct CharacterLiteral
?
struct DecimalLiteral
?
struct IntegerLiteral
?
?
enum LiteralResult
LiteralValue
InvalidLiteral
struct NaturalLiteral
?
?
Literal descriptors separate authored syntax from its eventual target type. Numeric spelling is normalized (digit separators are removed) but remains exact; decoded string/character/atom values are carried directly.
struct StringLiteral
?
Callbacks
interface ExpressibleByAtomLiteral(t)
interface ExpressibleByCharacterLiteral(t)
interface ExpressibleByDecimalLiteral(t)
interface ExpressibleByIntegerLiteral(t)
interface ExpressibleByNaturalLiteral(t)
interface ExpressibleByStringLiteral(t)
Functions
fn from_atom_literal(literal: AtomLiteral) -> LiteralResult(t)
fn from_character_literal(literal: CharacterLiteral) -> LiteralResult(t)
fn from_decimal_literal(literal: DecimalLiteral) -> LiteralResult(t)
fn from_integer_literal(literal: IntegerLiteral) -> LiteralResult(t)
fn from_natural_literal(literal: NaturalLiteral) -> LiteralResult(t)
fn from_string_literal(literal: StringLiteral) -> LiteralResult(t)
fn literal_decimal_to_float(spelling: List(Char)) -> Float
fn literal_int_to_float(value: Int) -> Float
Primitive Float conversions are explicitly lossy: choosing Float is the user's request to round an exact literal to IEEE-754. Decimal and custom targets never pass through these helpers.