OCaml-Parmap序列的串联

问题描述 投票:0回答:2

是否有任何方法可以连接类似于OCaml中内置列表的Parmap序列?

特别是我想做一些像这样的工作:

let yolo = [1;2;3]
let swag = [4;5;6]

let magic1 = Parmap.L yolo
let magic2 = Parmap.L swag

//below does not work
let result = magic1@magic2
list concatenation ocaml
2个回答
1
投票

您可以编写自己的串联实现(必要时甚至可以通过带有一些奇特名称的infix运算符)。只需“解构”装箱的值,合并它们并将结果放回适当的“容器”:

let (|@|) l1 l2 =
  match l1, l2 with
  | Parmap.L l1, Parmap.L l2 -> Parmap.L (l1 @ l2)
  | Parmap.A l1, Parmap.A l2 -> Parmap.A (Array.append l1 l2)
  | _, _ -> failwith "cannot concat oranges to apples"
;;

magic1 |@| magic2;;
- : int Parmap.sequence = Parmap.L [1; 2; 3; 4; 5; 6]

0
投票

我假设您是指this parmap

据我所知,这种操作不会真正从并行化中受益,因为您一次只能浏览一个链表。您的应用程序如何阻止您执行以下操作?

let yolo = [1;2;3]
let swag = [4;5;6]

let parseq = Parmap.L (yolo @ swag)
© www.soinside.com 2019 - 2024. All rights reserved.