[ create a new paste ] login | about

Link: http://codepad.org/xD8KLpgW    [ raw code | output | fork ]

OCaml, pasted on May 31:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
module Vector(T:sig val n : int end) : sig 
  type t = private float array
  val create : float -> t
  val add : t -> t -> t
end = 
struct
  type t = float array
  let create x = Array.make T.n x
  let add x y = Array.init T.n (fun i -> x.(i) +. y.(i))
end

module V3 = Vector(struct let n = 3 end)
module V4 = Vector(struct let n = 4 end)

(* let x : V3.t = [| 1. |] *)

let y = V3.add (V3.create 1.) (V3.create 2.)
let z = V3.add (V3.create 1.) (V4.create 2.)


Output:
1
2
Line 2, characters 6-30:
This fixed type is not an object or variant


Create a new paste based on this one


Comments: