Last active
December 9, 2023 16:28
-
-
Save guidorice/e85f739b8c7ce233311dc672fd452b76 to your computer and use it in GitHub Desktop.
try mojo auto-parameterization (mojo 0.6)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Wrappable: | |
""" | |
A nonsensical trait- which can be initialized with an int, or copied. | |
""" | |
fn __init__(inout self, x: Int): | |
... | |
fn __copyinit__(inout self, existing: Self): | |
... | |
@value | |
struct Wrappee[dtype: DType](Wrappable): | |
""" | |
Implements Wrappable, and stores an int as a SIMD value. | |
""" | |
var value: SIMD[dtype] | |
fn __init__(inout self, x: Int): | |
self.value = x | |
fn __copyinit__(inout self, existing: Self): | |
self.value = existing.value | |
struct Wrapper: | |
""" | |
A struct composed of a Wrappable trait struct. | |
""" | |
var value: Wrappable | |
fn __init__(inout self, w: Wrappable): | |
self.value = w | |
fn main(): | |
let wrappee = Wrappee[DType.float16](3.14) | |
let try_wrapper = Wrapper(wrappee) | |
# error: ^ cannot construct 'Wrapper' from 'Wrappee[f16]' value in 'let' initializer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment