【发布时间】:2020-08-12 09:18:39
【问题描述】:
我目前正在研究 Haskell,并试图了解一个使用 Haskell 实现加密算法的项目。在线阅读Learn You a Haskell for Great Good后,我开始理解该项目中的代码。然后我发现我被以下带有“@”符号的代码卡住了:
-- | Generate an @n@-dimensional secret key over @rq@.
genKey :: forall rq rnd n . (MonadRandom rnd, Random rq, Reflects n Int)
=> rnd (PRFKey n rq)
genKey = fmap Key $ randomMtx 1 $ value @n
这里的randomMtx定义如下:
-- | A random matrix having a given number of rows and columns.
randomMtx :: (MonadRandom rnd, Random a) => Int -> Int -> rnd (Matrix a)
randomMtx r c = M.fromList r c <$> replicateM (r*c) getRandom
并且PRFKey定义如下:
-- | A PRF secret key of dimension @n@ over ring @a@.
newtype PRFKey n a = Key { key :: Matrix a }
我能找到的所有信息源都说 @ 是 as-pattern,但这段代码显然不是那种情况。我查看了https://www.haskell.org/definition/haskell2010.pdf 上的在线教程、博客甚至Haskell 2010 语言报告。这个问题根本没有答案。
更多代码sn-ps也可以在这个项目中使用@这种方式找到:
-- | Generate public parameters (\( \mathbf{A}_0 \) and \(
-- \mathbf{A}_1 \)) for @n@-dimensional secret keys over a ring @rq@
-- for gadget indicated by @gad@.
genParams :: forall gad rq rnd n .
(MonadRandom rnd, Random rq, Reflects n Int, Gadget gad rq)
=> rnd (PRFParams n gad rq)
genParams = let len = length $ gadget @gad @rq
n = value @n
in Params <$> (randomMtx n (n*len)) <*> (randomMtx n (n*len))
我非常感谢您对此提供的任何帮助。
【问题讨论】:
-
这些是type applications。另见this Q&A。您还可以查看将它们引入代码的commit。
-
非常感谢您的链接!这些正是我正在寻找的。令人惊讶的是,您甚至可以识别代码的提交!非常感谢。只是好奇你是怎么找到它的? @MikaelF
-
Github 有自己的git blame 接口,它会告诉你最后一次修改每一行的提交。
-
非常感谢这个有用的提示:)
-
@MichaelLitchard 很高兴您能从中受益。我感谢善良的人们花时间帮助我。希望答案也可以帮助其他人。
标签: haskell symbols operator-keyword as-pattern