Silk

silk/numeric

Shared compile-time addition witness for generic algorithms over primitive integers.

When to use

Add an Integer bound when a generic function needs the + operator. Use the concrete integer modules directly when an algorithm also needs width-specific conversion, overflow, bitwise, or formatting operations.

Details

Witnesses are selected during specialization and create no Effect requirement, provider slot, or runtime dispatch. The interface intentionally exposes only the operation spelled by +; it does not attempt to erase the distinct ranges and conversion rules of each integer type.

Gotchas

The selected primitive operation keeps its ordinary overflow policy. Integer addition traps when the mathematical result is outside the selected type's range.

Examples

Add values through one generic contract

import silk.numeric as Numeric

pub fn main() -> i32 {
  return Numeric.add<i32>(40, 2)
}

Import as Integer with import silk.numeric.

Public declarations: 2.

Integer

pub interface Integer

Static addition contract for primitive integer values.

When to use

Use this interface when a generic algorithm needs only ordinary integer addition.

Details

Interfaces select compiler-known operations during specialization. They do not create effect requirements, provider slots, or runtime dispatch.

Operation add

operator + fn add(left: Self, right: Self) -> Self

Adds two values and traps if the selected integer type cannot represent the result.

Implementation Integer for u8

impl Integer for u8

Operation add

add = Intrinsic.u8Add

Implementation Integer for u16

impl Integer for u16

Operation add

add = Intrinsic.u16Add

Implementation Integer for u32

impl Integer for u32

Operation add

add = Intrinsic.u32Add

Implementation Integer for u64

impl Integer for u64

Operation add

add = Intrinsic.u64Add

Implementation Integer for usize

impl Integer for usize

Operation add

add = Intrinsic.usizeAdd

Implementation Integer for i8

impl Integer for i8

Operation add

add = Intrinsic.i8Add

Implementation Integer for i16

impl Integer for i16

Operation add

add = Intrinsic.i16Add

Implementation Integer for i32

impl Integer for i32

Operation add

add = Intrinsic.i32Add

Implementation Integer for i64

impl Integer for i64

Operation add

add = Intrinsic.i64Add

Implementation Integer for isize

impl Integer for isize

Operation add

add = Intrinsic.isizeAdd

add

pub fn add<T>(left: T, right: T) -> T

Adds two values and traps if the selected integer type cannot represent the result.

When to use

Use this function to call ordinary integer addition from generic code.

On this page