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.

Types

struct AtomLiteral

 struct AtomLiteral
   ?

struct CharacterLiteral

 struct CharacterLiteral
   ?

struct DecimalLiteral

 struct DecimalLiteral
   ?

struct IntegerLiteral

 struct IntegerLiteral
   ?
   ?

enum LiteralResult

 enum LiteralResult
   LiteralValue
   InvalidLiteral

struct NaturalLiteral

 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

 struct StringLiteral
   ?

Callbacks

interface ExpressibleByAtomLiteral(t)

 interface ExpressibleByAtomLiteral(t)

interface ExpressibleByCharacterLiteral(t)

 interface ExpressibleByCharacterLiteral(t)

interface ExpressibleByDecimalLiteral(t)

 interface ExpressibleByDecimalLiteral(t)

interface ExpressibleByIntegerLiteral(t)

 interface ExpressibleByIntegerLiteral(t)

interface ExpressibleByNaturalLiteral(t)

 interface ExpressibleByNaturalLiteral(t)

interface ExpressibleByStringLiteral(t)

 interface ExpressibleByStringLiteral(t)

Functions

from_atom_literal(literal: AtomLiteral) -> LiteralResult(t)

 fn from_atom_literal(literal: AtomLiteral) -> LiteralResult(t)

from_character_literal(literal: CharacterLiteral) -> LiteralResult(t)

 fn from_character_literal(literal: CharacterLiteral) -> LiteralResult(t)

from_decimal_literal(literal: DecimalLiteral) -> LiteralResult(t)

 fn from_decimal_literal(literal: DecimalLiteral) -> LiteralResult(t)

from_integer_literal(literal: IntegerLiteral) -> LiteralResult(t)

 fn from_integer_literal(literal: IntegerLiteral) -> LiteralResult(t)

from_natural_literal(literal: NaturalLiteral) -> LiteralResult(t)

 fn from_natural_literal(literal: NaturalLiteral) -> LiteralResult(t)

from_string_literal(literal: StringLiteral) -> LiteralResult(t)

 fn from_string_literal(literal: StringLiteral) -> LiteralResult(t)

literal_decimal_to_float(spelling: List(Char)) -> Float

 fn literal_decimal_to_float(spelling: List(Char)) -> Float

literal_int_to_float(value: Int) -> 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.