-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with types #22
Comments
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 |
You only need to use 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, |
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 |
That would feel more consistent 👍 |
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.
The text was updated successfully, but these errors were encountered: