archives

Multiple overloads of the bind operator

Hi! Let's say it makes a lot of sense in my domain to define the types WriteReference and ReadOnlyReference. I wish to create a monad that manipulates references, so my first idea was to define


(>>=) :: WriteReference a -> (a -> WriteReference b) -> WriteReference b
(>>=) :: WriteReference a -> (a -> ReadOnlyReference b) -> ReadOnlyReference b
(>>=) :: ReadOnlyReference a -> (a -> ReadOnlyReference b) -> ReadOnlyReference b
(>>=) :: ReadOnlyReference a -> (a -> WriteReference b) -> WriteReference b

return :: a -> ReadOnlyReference a

It looks ugly but it does its job, even though I fear it won't play nice with Haskell syntactic sugar for monads.

Does it make more sense to define Reference as a class, and then to define WriteReference and ReadOnlyReference as instances of this class, so that we can write something like:


data WR a = WR a
data RR a = RR a

class Reference r where get :: r a -> a

instance Reference WR where get (WR x) = x

instance Reference RR where get (RR x) = x

bind :: (Reference r1, Reference r2) => r1 a -> (a -> r2 b) -> r2 b
bind e k = let x = get e in k x

Can anyone help me understand why I should favor one approach over the other?

Thanks

Fighting Bit Rot with Types (Scala Collections)

didn't see it mentioned yet. i would excerpt the abstract were it not for the fact that the pdf is horribly broken such that no spaces are copied-and-pasted. yay usability.

the gist: statically typed collections library ends up with duplication, ironically? and new advances let it be excitingly refactored to make everybody happy again. i think that is interesting because i do believe static typing has some gotchyas.

Have tracing JIT compilers won?

I've been watching the interpreter and JIT compiler competitions a bit in the JavaScript and Lua worlds. I haven't collected much organized data but the impression I'm getting is that tracing JIT's are turning up as the winners: sometimes even beating programs statically compiled with GCC. Is there a growing body of evidence that tracing JIT compilers are the horse to bet on? Will a more static style JIT like Google's V8 be able to keep up?

Thanks,
Peter

[I promoted this item to the front page, since the discussion is highly interesting & informative. -- Ehud]