Open lehoff opened 1 month ago
Unfortunately we can't have real singleton (e.g type is the same as instance) this is not supported by Julia, so you need to explicitly write the instance (otherwise that's just a variant type). I was actually thinking this, maybe we should just remove the singleton syntax.
Not sure I understand what I need to do - could you give an example?
Follow up question: what would happen if I used ZeroZero()
instead of ZeroZero
? Can I still compare them for equality?
You only need to use ZeroZero()
in the pattern match (whenever you need to construct an instance), e.g
julia> Score.ZeroZero
Main.Score.ZeroZero
julia> Score.ZeroZero()
Main.Score.var"typeof(Score)"(Main.Score.var"##Storage#ZeroZero"())
this is what I meant there is no real singleton type, it was only a syntax sugar, ZeroZero()
is the actual instance.
actually maybe I'll just correct your script here
module TVJulia
@data MinuteOutcome begin
HomeGoal
AwayGoal
NoGoal
BothGoal
end
@data Score begin
ZeroZero
ZeroOne
OneZero
OneOne
Even
Plus(Int)
Minus(Int)
end
# const SCORES::Vector{Score.Type} = [
# Score.ZeroZero, Score.ZeroOne, Score.OneZero, Score.OneOne, Score.Even,
# Score.Plus(1), Score.Plus(2), Score.Plus(3), Score.Plus(4), Score.Plus(5),
# Score.Minus(1), Score.Minus(2), Score.Minus(3), Score.Minus(4), Score.Minus(5)]
function scores()
Score.Type[
Score.ZeroZero(), Score.ZeroOne(), Score.OneZero(), Score.OneOne(), Score.Even(),
Score.Plus(1), Score.Plus(2), Score.Plus(3), Score.Plus(4), Score.Plus(5),
Score.Minus(1), Score.Minus(2), Score.Minus(3), Score.Minus(4), Score.Minus(5)
]
end
function Base.:+(s::Score.Type, mo::MinuteOutcome.Type)
@match mo begin
MinuteOutcome.HomeGoal =>
@match s begin
Score.ZeroZero() => Score.OneZero()
Score.ZeroOne() => Score.OneOne()
Score.OneZero() => Score.Plus(2)
Score.OneOne() => Score.Plus(1)
Score.Even() => Score.Plus(1)
Score.Plus(n) => Score.Plus(min(n+1, 5))
Score.Minus(1) => Score.Even()
Score.Minus(n) => Score.Minus(n-1)
end
MinuteOutcome.AwayGoal =>
@match s begin
Score.ZeroZero() => Score.ZeroOne()
Score.ZeroOne() => Score.Minus(2)
Score.OneZero() => Score.OneOne
Score.OneOne() => Score.Minus(1)
Score.Even() => Score.Minus(1)
Score.Plus(1) => Score.Even()
Score.Plus(n) => Score.Plus(n-1)
Score.Minus(n) => Score.Minus(min(n+1, 5))
end
MinuteOutcome.BothGoal =>
@match s begin
Score.ZeroZero() => Score.OneOne()
Score.ZeroOne() => Score.Minus(1)
Score.OneZero() => Score.Plus(1)
Score.OneOne() => Score.Even()
_ => s
end
MinuteOutcome.NoGoal() => s
end
end
maybe we should just remove the singleton syntax.
That would feel more consistent :+1:
I have define the following:
But I am running into problems - one after the other.
When I try to use my
+
operator I get:This leaves me rather confused.
Happy to conduct further investigations if that would be of any help.