Hacker News new | ask | show | jobs
by jules 5423 days ago
The extra parentheses around the evaluates are not necessary, except in the last line. I'm fond of this pairing heap in F#:

    type 't heap = Empty | Heap of 't * 't heap list

    let findmin (Heap(x,_)) = x
    let merge h1 h2 = 
      match (h1,h2) with
      | Empty,h | h,Empty -> h
      | Heap(x,h1s),Heap(y,h2s) -> if x < y then Heap(x,h2::h1s) else Heap(y,h1::h2s)
    let deletemin (Heap(_,hs)) = List.fold merge Empty hs
    let insert h x = merge h (Heap(x,[]))