Can application state type be a typeclass? #514
-
|
If it is a typeclass, then I can replace a sum type with typeclass instances. I haven't tried to make this happen, but is this possible? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 12 replies
-
|
You can embed typeclass in an existential type, but I will have to try existential type with brick. |
Beta Was this translation helpful? Give feedback.
-
|
I finally found the answer. The answer is to use a product type as the application state. For example, data State = {
draw :: ...
, handleEvent :: ....
}One mode can set application state to a different With this, I can finally remove case statement. |
Beta Was this translation helpful? Give feedback.
I guess I'm not clear on why you think this is a problem. I don't think it's a problem, so I don't see it as something to be avoided.
That's right; I'm not even sure this makes any sense. At least if a type class was involved, I'm not sure how that would add any benefit. As for
or some sort of polymorphism, that's what thestype is for inApp. The polymorphism is already there.One of the big drawbacks of using a type class for, say, existentially quantified types, is that they cause all kinds of trouble when you have to unpack constructors and convince the c…