I noticed that when he got to the balance function he says something
to the effect of "If Haskell had or-patterns this is how you could
write this function more concisely". I noticed that this paper was
written in '93 so I figured that maybe Haskell has Or-patterns now,
but a google search didn't uncover anything conclusive - there was
some 2005 post by Simon Peyton-Jones saying that he'd add them if
anyone came up with an implementation. So has anyone come up with an
implementation?
This is how the balance function came out in OCaml:
let rec balance t = match t with
T(B, T(R, T(R, a,x,b), y, c), z, d) | T( B, T(R,a,x,T(R,b,y,c)),z,d) |
T(B,a,x, T(R,T(R,b,y,c),z,d) ) | T(B,a,x,T(R,b,y,T(R,c,z,d))) ->
T(R, T(B,a,x,b), y, T(B, c,z,d))
| _ -> t ;;
Phil