Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Oct 14th, 2010  |  syntax: OCaml  |  size: 0.66 KB  |  hits: 1,203  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. module Ops2 =
  2.   let inline (|!>) a b = b !a
  3.   let inline (<==) a b = a := b !a
  4.   let inline (|?>) a b = match a with Some x -> Some(b x) | _ -> None
  5.   let inline (|?) a b = match a with Some x -> x | _ -> b()
  6.  
  7.   (* Delayed (C# style) null coalescing for Option types *)
  8.   None |? fun()-> 1
  9.  
  10.   (* Option piping, same as |> put for option types *)
  11.   Some 1 |?> (fun x -> x + 1)
  12.   None |?> (fun x -> x + 1)
  13.  
  14.   (* ref update operator, applies the right operand to the left
  15.      and stores the result in the left operand *)
  16.   let x = ref 1
  17.   x <== (fun x -> x + 1)
  18.   printfn "%A" x
  19.  
  20.   (* ref piping, same as |> but for refs *)
  21.   x |!> (fun x -> x + 1)