作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试打印 autocorrelation 结果的不同组成部分在不同的线路上:
import Data.Vector as V
import Statistics.Autocorrelation
import Data.Typeable
sampleA = [1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4]
main = do
let res = autocorrelation $ V.fromList sampleA
putStr "Type of result of autocorrelation test: "
print $ typeOf res
print res
-- Prelude.mapM_ print res -- not working;
Type of result of autocorrelation test: ((Vector Double),(Vector Double),(Vector Double))
([1.0,2.5e-2,-0.45,-0.325,0.5,0.125,-0.15],[1.0,-1.3255000000000001,-1.4039375473415425,-1.442999810318651,-1.5311377955236107,-1.5364636906417393,-1.544097864842309],[1.0,1.0755000000000001,1.1539375473415425,1.192999810318651,1.2811377955236107,1.2864636906417393,1.294097864842309])
• No instance for (Foldable ((,,) (Vector Double) (Vector Double)))
arising from a use of ‘Prelude.mapM_’
• In a stmt of a 'do' block: Prelude.mapM_ print res
In the expression:
do { let res = autocorrelation $ fromList sampleA;
putStr "Type of result of autocorrelation test: ";
print $ typeOf res;
print res;
.... }
In an equation for ‘main’:
main
= do { let res = ...;
putStr "Type of result of autocorrelation test: ";
print $ typeOf res;
.... }
最佳答案
最简单的就是模式匹配。
main = do
let (a,b,c) = autocorrelation $ V.fromList sampleA
print a
print b
print c
关于haskell - 在这种情况下如何使用 mapM_,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57931873/
我对Haskell优化在内部的工作方式不太了解,但我一直在使用过滤器,希望它们可以被优化为等效于C++的简单过滤器。例如 mapM_ print $ filter (\n -> n `mod` 2 =
我正在尝试打印 autocorrelation 结果的不同组成部分在不同的线路上: import Data.Vector as V import Statistics.Autocorrelation
我是一名优秀的程序员,十分优秀!