module Dict = structinclude Hashtbl let ( .%{} ) tabl index = find tabl index let ( .%{}<- ) tabl index value = add tabl index value endlet dict = let dict = Dict.create 10 inlet () = dict.Dict.%{"one"} <- 1; letopen Dict in dict.%{"two"} <- 2 in dict
let (.%[;..]) = Bigarray.Genarray.get let (.%{;..}) = Bigarray.Genarray.get let (.%(;..)) = Bigarray.Genarray.get
当索引字面量包含一个用分号分隔的具有两个或多个元素的表达式列表时,就会调用它
let sum x y = x.%[1;2;3] + y.%[1;2] (* 等价于 *)let sum x y = (.%[;..]) x [|1;2;3|] + (.%[;..]) y [|1;2|]
特别是,这种多索引表示法可以统一处理 Genarray 和多维数组的其他实现的索引。
module A = Bigarray.Genarray let (.%{;..}) = A.get let (.%{;..}<- ) = A.set let (.%{ }) a k = A.get a [|k|] let (.%{ }<-) a k x = A.set a [|k|] x let syntax_compare vec mat t3 t4 = vec.%{0} = A.get vec [|0|] && mat.%{0;0} = A.get mat [|0;0|] && t3.%{0;0;0} = A.get t3 [|0;0;0|] && t4.%{0;0;0;0} = t4.{0,0,0,0}