let forA arr func = Array.iter func arr
let forL lst func = List.iter func lst
let forStream strm func = Stream.iter func strm
external extern_identity : 'a -> 'a = "%identity"
let identity = extern_identity
let some x = Some x
let ( >> ) x f = f x
let ( & ) f x = f x
let ( % ) f g = fun x -> f (g x)
let ( $ ) = ( % )
let ( %% ) f g = fun x y -> f (g x y)
let ( %%% ) f g = fun x y z -> f (g x y z)
let ( /* ) x y = y x
let ( */ ) x y = x y
module Int_as_int =
struct
let ( + ) = Pervasives.( + )
let ( - ) = Pervasives.( - )
let ( * ) = Pervasives.( * )
let ( / ) = Pervasives.( / )
let ( ~- ) = Pervasives.( ~- )
end
module Float_as_float =
struct
let ( +. ) = Pervasives.( +. )
let ( -. ) = Pervasives.( -. )
let ( *. ) = Pervasives.( *. )
let ( /. ) = Pervasives.( /. )
let ( ~-. ) = Pervasives.( ~-. )
end
module Int32_as_int =
struct
let ( + ) = Int32.add
let ( - ) = Int32.sub
let ( * ) = Int32.mul
let ( / ) = Int32.div
let ( ~- ) = Int32.neg
end
module Int64_as_int =
struct
let ( + ) = Int64.add
let ( - ) = Int64.sub
let ( * ) = Int64.mul
let ( / ) = Int64.div
let ( ~- ) = Int64.neg
end
module Int_as_float =
struct
let ( +. ) = Pervasives.( + )
let ( -. ) = Pervasives.( - )
let ( *. ) = Pervasives.( * )
let ( /. ) = Pervasives.( / )
let ( ~-. ) = Pervasives.( ~- )
end
module Float_as_int =
struct
let ( + ) = Pervasives.( +. )
let ( - ) = Pervasives.( -. )
let ( * ) = Pervasives.( *. )
let ( / ) = Pervasives.( /. )
let ( ~- ) = Pervasives.( ~-. )
end
module Int32_as_float =
struct
let ( +. ) = Int32.add
let ( -. ) = Int32.sub
let ( *. ) = Int32.mul
let ( /. ) = Int32.div
let ( ~-. ) = Int32.neg
end
module Int64_as_float =
struct
let ( +. ) = Int64.add
let ( -. ) = Int64.sub
let ( *. ) = Int64.mul
let ( /. ) = Int64.div
let ( ~-. ) = Int64.neg
end
module Int_as_int_overflow =
struct
exception Overflow
let ( + ) a b =
let c = a + b in
if (a lxor b) lor (a lxor (lnot c)) < 0 then c else raise Overflow
let ( - ) a b =
let c = a - b in
if (a lxor (lnot b)) lor (b lxor c) < 0 then c else raise Overflow
let ( * ) a b =
let c = a * b in
if Int64.of_int c = Int64.mul (Int64.of_int a) (Int64.of_int b)
then c else raise Overflow
let ( / ) a b =
if a = min_int && b = -1 then raise Overflow else a / b
let ( ~- ) x =
if x <> min_int then -x else raise Overflow
end