Skip to content

Conversation

Tortar
Copy link
Member

@Tortar Tortar commented Sep 10, 2025

Fixes #120

@Tortar
Copy link
Member Author

Tortar commented Sep 10, 2025

Example

julia> using LightSumTypes

julia> @sumtype X(Bool, Int, Vector{Bool}, Vector{Int})

julia> xs = [X([1,2]), X(true)]
2-element Vector{X}:
 X([1, 2])
 X(true)

julia> sum_(x::X, y::X, z) = apply(sum_, (x, y, z))
sum_ (generic function with 1 method)

julia> sum_(x, y, z) = sum(x) + sum(y) + z
sum_ (generic function with 2 methods)

julia> sum_(xs[1], xs[2], 2.0)
6.0

julia> @code_warntype sum_(xs[1], xs[2], 2.0)
MethodInstance for sum_(::X, ::X, ::Float64)
  from sum_(x::X, y::X, z) @ Main REPL[4]:1
Arguments
  #self#::Core.Const(Main.sum_)
  x::X
  y::X
  z::Float64
Body::Float64
1%1 = Main.apply::Core.Const(LightSumTypes.apply)
│   %2 = Main.sum_::Core.Const(Main.sum_)
│   %3 = Core.tuple(x, y, z)::Tuple{X, X, Float64}%4 = (%1)(%2, %3)::Float64
└──      return %4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Function to perform branching automatically to solve inference failures
1 participant