Case statement equivalent?


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…

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

struct Bar

printtype(y::Foo) = println("it's a int: $y")
printtype(y::Bar) = println("it's a float: $y")