deimos-lang/sketching/march_2026/traits_and_ints.dm
2026-03-20 20:39:30 -05:00

48 lines
800 B
Plaintext

trait Add<R = Self>
type Output = Self
fn add(other: R) -> Self::Output
end
intrinsic class Int end
intrinsic class Double end
impl Add for Int
fn add(other: Self) -> Self
self + other
end
end
impl Add<Double> for Int
type Output = Double
fn add(other: Double) -> Double
self + other
end
end
impl Add for Double
fn add(other: Self) -> Self
self + other
end
end
impl Add<Int> for Double
fn add(other: Int) -> Self
self + other
end
end
fn add_rough_pi(a: impl Add<Double>) -> Double = a + 3.14
fn concat<T: impl Add<U>, U>(a: T, b: U) -> T::Output
a + b
end
fn main()
let x = add_rough_pi(3)
println(x) // 6.14
let y = concat(1, 2) // 3
let z = concat("Hello, ", "World!") // "Hello, World!"
end