datatype 'a 'b either =
  Left of 'a
| Right of 'b

ML, 1973.  Pascal is only 3 years older, but much much sillier.

On Tue, Oct 30, 2012 at 11:39 PM, Cédric Beust ♔ <ced...@beust.com> wrote:
> I hope you're not suggesting that I was contrasting the quality of a piece
> of code that's forty years old with one written in a modern programming
> language...
>
> --
> Cédric
>
>
>
>
> On Tue, Oct 30, 2012 at 7:34 PM, Ricky Clarkson <ricky.clark...@gmail.com>
> wrote:
>>
>> The difference being that your Pascal example has no notion of one
>> side being the real side, hence it being useful for subverting the
>> type system, and an Either has that defined and doesn't allow any
>> subversion, but lets you abstract over it being one thing or the
>> other.  In C it can be used for 'evil' too but a common approach is to
>> have a tag saying what the type really is.
>>
>> On Tue, Oct 30, 2012 at 11:25 PM, Cédric Beust ♔ <ced...@beust.com> wrote:
>> > Bouncing off another topic mentioned in the latest podcast: union types.
>> > Yes, C had them but the first time I was exposed to them was in Pascal,
>> > and
>> > the discussion on the podcast reminded me of an awesome hack that blew
>> > my
>> > mind a very long time ago.
>> >
>> > Pascal was well known to be very strict and safe. Among other things, it
>> > didn't let you access the memory directly, which was a big deal in the 8
>> > bit
>> > era where memory protection was a distant dream and PEEK and POKE were
>> > how
>> > you wrote games.
>> >
>> > And then, one day, somebody found a way to address the memory using
>> > standard
>> > Pascal. Here is the trick (from memory, so it's probably not quite
>> > correct):
>> >
>> > type
>> >   b = record
>> >         x : array[1..65536] of ^integer;
>> >         y : integer;
>> >       end;
>> >
>> > This declares a union type that is made of either an array of 65k
>> > pointers
>> > to integers or a single integer. Then you initialize this record in its
>> > "x"
>> > side with the memory address you want to peek and you access it by using
>> > the
>> > "x" side of the record.
>> >
>> > It took me months to understand what this code did, but what a
>> > revelation it
>> > was when it finally clicked...
>> >
>> > By the way, these types are formally known as "sum types" (Either is one
>> > of
>> > them).
>> >
>> > --
>> > Cédric
>> >
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Java Posse" group.
>> > To post to this group, send email to javaposse@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > javaposse+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/javaposse?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Java Posse" group.
>> To post to this group, send email to javaposse@googlegroups.com.
>> To unsubscribe from this group, send email to
>> javaposse+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/javaposse?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Java Posse" group.
> To post to this group, send email to javaposse@googlegroups.com.
> To unsubscribe from this group, send email to
> javaposse+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/javaposse?hl=en.

-- 
You received this message because you are subscribed to the Google Groups "Java 
Posse" group.
To post to this group, send email to javaposse@googlegroups.com.
To unsubscribe from this group, send email to 
javaposse+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to