
Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [tlug] STM (was: Re: work times & accommodation @tokyo)
Curt Sampson writes:
> On 2008-07-30 03:46 +0900 (Wed), Stephen J. Turnbull wrote:
>
> > Curt Sampson writes:
> >
> > > The point is, the compiler's type checker in Java is not poweful enough
> > > to tell you when you've used your library incorrectly,
> >
> > That's a pretty strong assertion.
>
> Indeed, it is. But anybody here is free to prove me wrong by showing me
> an example of how this might be done.
Hey, you acknowledged that the transactional aspect could be
implemented. So the question is how to arrange for type-checking.
Make it a separate class, with private members for the value and the
log. The accessors and mutators take care of protecting it from
impure operations (ie, maintaining the log); pure operations are
implemented as methods.
True, Haskell's monads will allow you to let the compiler do a lot of
the typechecking work *inside* the library implementation, and Java's
won't. However, I don't see why Java wouldn't be able to tell you
you're *using* the library incorrectly by throwing a type mismatch
when you try to process a TVar with an unsafe function.
> The really short explanation is that Haskell forces you to
> distinguish pure and impure operations,
I don't think this is true for STM, since it's not a cut-and-dried
situation like with the IO monad.
> and type your impure operations.
Well, I can't be absolutely sure that Java can do this, but C++ will.
It's very painful, but there is such code in XEmacs that is used to
static check int-char confusion. You have to override a huge number
of conversions that are provided by default, of course. I think it
would actually be quite a bit easier to create a TVar class. (This is
where monads come in, of course; they automatically override -- turn
into errors -- a lot of compositions that C family languages have to
specify one by one.)
> [This] is not the place for a long tutorial paper on the Haskell
> type system, monads, and so on anyway.
I think you're underestimating how much I know about formal type
systems.
Home |
Main Index |
Thread Index