Now I'm trying to write a toy-language-frontend using Haskell.
And there are two entities:
- rvalue - variables and integer-literals (for example)
- lvalue - variables only.
I think the most natural way to describe this in data structures is:
data LValue = Var String
data RValue = Var String | Lit Int
(I really think this is the best approach - not verbose and strict enough thanks exhaustive pattern matching) But ghc shows me error: "multiple declarations of Var".
So the question is: what's the most straightforward way in Haskell to describe what I want?
Noteces: There is a similar question 11 years ago with no good answer. But has anything changed for 11 years? One value constructor belonging to two different types
And there is some other approaches with "packing" LValue again (and again and again in less-toy-language) in data-constructor like this:
data LValue = Var String
data RValue = LValue LValue | Lit Int
But I doubt is this good way: AST-transformation code becomes too verbose.