问题标签 [haskell-vector]
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 - 如何将具有 2 个值的向量拆箱
我正在尝试按照此处给出的 wilcoxonMatchedPairTest 进行:
但是,我收到以下错误:
显然,我需要在这里拆箱矢量。我尝试使用#
如下:
但它不起作用。问题出在哪里,如何解决?谢谢你的帮助。
haskell - 如何指定固定大小的向量的类型?
我正在尝试Data.Vector.Fixed
用作函数的输入,并且正在努力在类型签名中指定向量的维度。
例如,我正在尝试执行以下操作:
并因此使用定义的 peano 数指定向量的维度 (8) Data.Vector.Fixed.Cont
。
但是,尝试编译它会产生类型不匹配错误:
如何在类型签名中指定固定向量的大小?
haskell - 如何解冻、变异、然后重新冻结 Haskell 向量?
我正在完成一个关于 Haskell Vectors 的教程,作为练习,它要求你重新实现Data.Vector.Unboxed.modify
usingrunST
和“教程前面介绍的函数”,我认为它是thaw
& freeze
。
这是我尝试过的:
哪个得到编译错误:
我认为重要的一点是:
看看我的尝试modify
:
我想表达的是:
- 解冻
Vector
成一个MVector
- 执行突变
- 冻结成一个新的
Vector
如果我注释掉我尝试执行突变的位置:
代码编译并运行以生成未修改的向量。
因此,我尝试应用有状态操作sa
来修改可变向量的方式存在问题mv
。
查看类型以及thaw 和 freeze 的文档:
因此,该do
块位于 typeclass 的 monadm
中PrimMonad
。
我的想法是,ST s
将与它“排队”以执行突变......
我尝试将其绑定到一个洞:
但这并没有什么不同,考虑到它,你不会期望它...
我认为这是关于 monad 转换器的一般问题。我需要在这里做一些提升吗?
那么我需要做什么来用我的来执行可变向量的突变sa
?
haskell - Unboxed vector of newtype hangs in basicUnsafeNew
I'm trying to store a simple vector of three-dimensional points in space. To do this, I'm newtype
-ing a custom Point
and manually implement the Data.Vector.Unboxed.Vector
and Data.Vector.Unboxed.Mutable
instances for it.
However, for some reason, any attempt to use such a vector ends up in an infinite loop in basicUnsafeNew
. The following program will hang:
The code requires the vector
and linear
packages.
I pushed this code as MWE with stack
support here for convenience: https://github.com/jtprobst/vectortest
Simply call stack run
and observe the endless traces of "unsafe new".
I'm running with stack --version
Version 2.5.1, Git revision d6ab861544918185236cf826cb2028abb266d6d5 x86_64 hpack-0.33.0
Note that all methods except basicUnsafeNew
on the vector default to error
instead of doing anything useful. This is just to exclude the possibility of them interfering in any way. It also hangs if I use the typical default implementations for these methods (for example as described in this answer on SO, point number 2).
Any hints as to what I'm doing wrong are highly appreciated.