问题标签 [fsharp-typeclasses]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
haskell - 将 Haskell (monadic) 翻译成 F#
帮我翻译下面的 Haskell 代码块。run函数生成对应于抽象为 Pattern 的给定正则表达式的文本字符串。您可以在下面的 F# 代码块中看到 Pattern 类型的声明。您可以测试运行功能,例如
下面我给出我糟糕的尝试。它工作但不正确。问题在以下。假设parse产生这样的Pattern
解析“\\d\\d”;;验证它:Pattern = POr [PConcat [PEscape (DoPa 1,'d'); PEscape (DoPa 2,'d')]]
和
解析“\\d{2}”;;验证它:Pattern = POr [PConcat [PBound (2,Some 2,PEscape (DoPa 1,'d'))]]
所以喂两种模式运行我希望收到seq [['2'; '2']; ['2'; '3']; ['2'; '1']; ['2'; '4']; ...]对应于seq ["22"; “23”;“21”;“24”;...](每个字符串 2 个符号)
这在第一种情况下是有效的,
POr [PConcat [PEscape (DoPa 1,'d'); PEscape (DoPa 2,'d')]] |> 运行;; 验证它:seq = seq [['2'; '2']; ['2'; '3']; ['2'; '1']; ['2'; '4']; ...]
序列 ["22"; “23”;“21”;“24”;...]
但不是在第二个
POr [PConcat [PBound (2,Some 2,PEscape (DoPa 1,'d'))]] |> 运行;; 验证它:seq = seq [['2']; ['2']; ['2']; ['3']; ...]
序列 ["2"; “2”,“2”;“3”、“2”;“1”、“2”;"4";...](每个字符串 1 个符号)
我使用以下子句测试了不同的变体:
但一切都是徒劳的。我无法弄清楚有效的翻译。
- 也许我应该使用字符串或数组而不是字符列表。
-而且我认为 Seq 非常类似于 Control.Monad.Stream。这样对吗?
提前感谢您的帮助
haskell - 使用 fsharp-typeclasses 创建一个适用于任意 monad 的函数
我正在尝试composM
从论文中实现几乎组合函数的模式,它接受任意单子并对其进行处理。在 Haskell 中,代码是:
我尝试使用fsharp-typeclasses 和下面的代码:
但我得到类型推断错误:
我试图通过 fsharp-typeclasses 实现的目标是什么?还是我必须将函数限制为仅使用特定的 monad?