小编use*_*560的帖子

Haskell:无法推断使用"cos"引起的(浮动t)

我正在学习Haskell,我试图根据我在Internet上找到的资源实现一些量子门.目前,我成功实现了Z门,X门,H门,但我在实现旋转门时遇到了问题.

U = [[cos t  -sin t] 
     [sin t  cos t ]]
Run Code Online (Sandbox Code Playgroud)

我写的代码:

type Vector a = [a]
type Matrix a = [Vector a]
vectorToComplex :: Integral a => Vector a -> Vector (Complex Double)
vectorToComplex = map (\i -> fromIntegral i:+0.0)

matrixToComplex :: Integral a => Matrix a -> Matrix (Complex Double)
matrixToComplex = map vectorToComplex
--Z Gate
gateZ :: Matrix (Complex Double)
gateZ = matrixToComplex [[1,0],[0,-1]]
Run Code Online (Sandbox Code Playgroud)

我尝试以与实现Z-gate相同的方式实现gateR(旋转门):

gateR :: Integral t => t -> Matrix (Complex Double)
gateR …
Run Code Online (Sandbox Code Playgroud)

haskell

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

标签 统计

haskell ×1