ModularM
Modular3y ago
9 replies
Aziz

Check types

How to check a type of a variable?
type(x)
raises an error
isinstance(1, Int)
also raises an error

I was only able to print the types using:
struct print_type:
    fn __init__(inout self, type:Int):
        print("Int")
    fn __init__(inout self, type:Float64):
        print("Float64")
    # ...

However it seems to be not possible to return the type instead of just printing it
struct print_type:
    fn __init__(inout self, type:Int) -> AnyType:
        print("Int")
        return Int. # Error
Screenshot_2023-09-16_at_1.05.26_PM.png
Was this page helpful?