小编Jul*_*ard的帖子

生成的折叠类型、迭代器和映射与 ppx_deriving 文档不一致

我正在努力正确设置我的 OCaml 环境以使用 ppx 派生器映射、折叠和迭代,如下所示:https : //github.com/ocaml-ppx/ppx_deriving#plugins-iter-map-and-fold

我的最小示例在这里(我使用 Base,因为这是我在更广泛的项目中使用的库):

open Base;;

type data = Row of float array | Dim of data array
[@@deriving iter, map, fold, show];;

let t = Row [|2.;2.|];;
pp_data Caml.Format.std_formatter t;;
map_data (fun x -> x +. 1.) t;;
pp_data Caml.Format.std_formatter t;;
Run Code Online (Sandbox Code Playgroud)

以下代码编译为 ocamlfind ocamlc -package base -package ppx_deriving.iter -package ppx_deriving.map -package ppx_deriving.fold -package ppx_deriving.show -linkpkg -g test.ml && ./a.out; 我收到一个编译错误,指出map_data类型为data -> data。但是根据文档和我的一般知识,map得到一个函数和一个可映射的结构,这里似乎不是这种情况。在 utop 中测试这个给了我同样的错误。

有什么我想念的吗?

先感谢您 …

ocaml fold ocamlfind

5
推荐指数
1
解决办法
74
查看次数

编写适当的自定义读取实例

哈斯凯勒同学们大家好,

\n\n

我现在正在学习 Haskell 一个月,并且正在努力为个人数据类型创建自定义读取实例。

\n\n

我遵循了这一点以及Learn Yourself a Haskell 中的相关章节,这是我的代码片段。

\n\n
data Position      =  Position (Absc,Ordn) deriving (Show)\ninstance Read (Position) where\nreadsPrec _ input =\n    let absc = List.filter (/=\'(\') $ takeWhile (/=\',\')\n        ordn = List.filter (/=\')\') $ tail (dropWhile (/=\',\') )\n    in (\\str -> Position ( (read (absc str) :: Int)\n                       , (read (ordn str) :: Int) ) ) input\ntype Absc = Int\ntype Ordn = Int\n
Run Code Online (Sandbox Code Playgroud)\n\n

我的目标是解析输入"(1,3)"以输出类似的内容Position (1,3)

\n\n

但是,我收到以下错误消息:

\n\n …

haskell currying typeclass deriving

1
推荐指数
1
解决办法
766
查看次数

标签 统计

currying ×1

deriving ×1

fold ×1

haskell ×1

ocaml ×1

ocamlfind ×1

typeclass ×1