For something I'm writing I want to define a state. A player is either in an active state, a startup state, or an endlag state. And there are functions for transitioning between states. Right now, I have all of these datatypes defined as separate, but they are all conceptually similar; for example, a player has a state, as in the base type, but in practice that state is an active state, or an endlag state. The plain old data keyword won't help for this, and in fact I hear class is more useful. But I'm not trying to create an abstraction over all types, only states. Some code if it helps:
class State a where --This is what needs fixing transition :: a -> a data StandingState = Crouching | Standing | Jumping deriving (Show, Eq, State) data DefaultState = Idle deriving (Show, Eq, State) data Hitstun = Hurt deriving (Show, Eq, State) data Knockeddown = Knockdown deriving (Show, Eq, State) data Wakeup = Getup deriving (Show, Eq, State) data StartupState = LightStartup | MediumStartup | HeavyStartup | GrabStartup | RollStartup | SandStartup | CurseStartup | RollSandStartup | RollCurseStartup | DashStartup | DiveStartup deriving (Show, Eq, State) data ActiveState = Walk | Block | Light | Medium | Heavy | Grab | Sand | Curse | Dash | Roll | RollCurse | RollSand | Dive deriving (Show, Eq, State) data EndlagState = LightEndlag | MediumEndlag | HeavyEndlag | GrabEndlag | RollEndlag | SandEndlag | CurseEndlag | RollSandEndlag | RollCurseEndlag | DashEndlag | DiveEndlag | LandLag | JumpSquat | BlockEndlag | WalkEndlag deriving (Show, Eq, State) --From here, the newtype keyword is used to define valid states while crouching or in the air. Additionally, functions are used to translate between types, but this should be enough for someone to get what I'm talking about
submitted by /u/Southern-Reality762
[link] [comments]