KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I just started learning Haskell. I think I've got the basics down, but I want to make sure I'm actually forcing myself to think functionally too. data Dir = Right | Left | Front | Back | Up | Down deriving (Show, Eq, Enum) inv Right = Left inv Front = Back inv Up = Down Anyway, the jist of what I'm trying to do is to create a function to map between each "Dir" and its opposite/inv. I know I could easily continue this for another 3 lines, but I can't help but wonder if there's a better way. I tried adding: inv a = b where inv b = a but apparently you can't do that. So my question is: Is there either a way to generate the rest of the inverses or an altogether better way to create this function? Thanks much.
Tags (comma-separated)
Save Edits
Cancel