haskell "Dot Hack"

标签 haskell

Wiki page for Sudoku solutions ,一种解决方案声称使用“Dot Hack”。链接的 Github 页面不再可用,我在别处找不到任何关于它的信息。

这是关于什么的?它有什么作用?如何?

最佳答案

我猜他指的是以下行:

import Prelude hiding ((.))

禁用正常 (.)功能组合的运算符。相反,使用了另一个具有相同名称的运算符,可能是从实用程序模块 T.T 导入的。 .此运算符的行为类似于 OOP 语言:
pretty_output solution = solution.elems.map(show).in_group_of(9)
    .map(unwords).unlines

(我认为)通常看起来像
pretty_output solution = (unlines . map unwords . in_group_of 9 . map show . elems) solution

该运算符的工作方式与 |> 相同。 F# 中的运算符:
(|>) :: a -> (a -> b) -> b
x |> f = f x

它用于通过函数传递值(并且更具可读性和更好的功能风格,imo):
pretty_output solution = solution |> elems |> map show |> in_group_of 9 |> map unwords |> unlines
(|>)也与 flip ($) 相同.

编辑:不知何故,这个“被黑”的运算符已经存在于 Haskell 中。相同的合成行为可以通过 Control.Category 中的从左到右合成运算符来实现。 :
g x = x |> (f1 >>> f2 >>> f3)

不过,此管道仅起作用,实际上只是 f >>> g = g . f .

关于 haskell "Dot Hack",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11258364/

相关文章:

haskell - Haskell 中队列的使用(模块)

haskell - 为什么非详尽的守卫会导致无可辩驳的模式匹配失败?

haskell - 在循环时调用具有新值的函数

haskell - func = elem [1..10] 在 GHCi 中工作但无法编译

testing - QuickCheck:生成平衡样本的嵌套数据结构的任意实例

haskell - Agda 中的递归方案

haskell - 手动将 SCC 附加到整个函数?

haskell - 具有功能更新的数组的最有效实现是什么?

haskell - 尝试安装 hs-ffmpeg haskell 包找不到 libdc1394

haskell - 使用 Haskell 下载维基百科标记