data A = ...data B = ...data AorB = A | B
But did you already understand what's happening?> data AorB = A | Bis pretty much like an enumeration the same as> data DayOfTheWeek = Monday | Tuesday | Wednesday | ... | Sundayit stores no values of any type, you could even have DayOfTheWeek asa constructor in the same declaration of the data DayOfTheWeek, because they arein different scopes:> data DayOfTheWeek = Monday | Tuesday | Wednesday | ... | Sunday | DayOfTheWeekand by no means, that A or B on the right hand side of your data AorB are referencing thedata A nor the data B...In the end, you could have:data A = Aconstructor Intdata B = Bconstructor Intdata AorB = A A | B Bf :: Int -> AorBf x| even x = A (Aconstructor x)| otherwise = B (Bconstructor x)I just added a Value to each constructor of the data AorB, which happens to benamed the same as the value they store...What I'm about to do is something I haven't tried, but I don't see why it shouldn'tcompile:> data Try = Int Intin data Try you have a constructor named Int, and it has a value of type Int,I'm trying to explain it the best I can, but I don't know if I managed to do itclearly, please let me know if there's something where I wasn't clear enough.
Hector
On Tue, Dec 14, 2010 at 4:40 PM, Russ Abbott <russ.abbott@gmail.com> wrote:My typo started this most recent confusion. When I wrote
data AorB = A | Bcompiles with error.That raises the question of what it really means!I meant to saydata AorB = A | B
compiles without error.That raises the question of what it really means!
-- RussOn Tue, Dec 14, 2010 at 1:04 PM, Tobias Brandt <tob.brandt@googlemail.com> wrote:On 14 December 2010 22:02, Hector Guilarte <hectorg87@gmail.com> wrote:I believe you. As I said, I was talking crap :-)
> Tobias you replied at the same time I was answering, you did explained what
> is happening,
> however, you said something which isn't right. As I mentioned before, "Type
> Constructors" and
> "Value Constructors" are in different scopes, and so, their names can be
> used again...
> if you don't believe me, give it a try with this example.