What I want to do…
data = Foo Int | Bar Float
case x
Foo y → print “it’s an int”, y
Bar y → print “it’s a float”, y
Is there a way to approximate this ?
What I want to do…
data = Foo Int | Bar Float
case x
Foo y → print “it’s an int”, y
Bar y → print “it’s a float”, y
Is there a way to approximate this ?
The magic of search…
https://matchjl.readthedocs.io/en/latest/
Not exactly sure how I stumbled upon it…
Match.jl provides quite powerful pattern matching capabilities, but if you only want to choose action based on types (or other fixed parameters), you can use great Julia’s multiple dispatch:
struct Foo
x::Int
end
struct Bar
x::Float64
end
printtype(y::Foo) = println("it's a int: $y")
printtype(y::Bar) = println("it's a float: $y")