我注意到有关Voidhaskell Data.Void模块中的类型的一件事,这很奇怪,我非常想知道为什么它是这样的.未定义应该是一个存在于每种类型的值(在我的理解中),和
undefined :: Type
Run Code Online (Sandbox Code Playgroud)
应该屈服
*** Exception: Prelude.undefined
Run Code Online (Sandbox Code Playgroud)
它适用于我尝试的每种数据类型,除了Void.
undefined :: Void根本没有终止,相同absurd undefined.现在我认为这不是一个问题,因为它Void代表了一种不会发生的价值,但我仍然想知道导致这种行为的原因.
我尝试使用 haddock 为库生成文档,虽然它可以工作,但它不会链接属于 GHC/标准库的任何类型并发出此错误:
Warning: The documentation for the following packages are not installed. No
links will be generated to these packages: array-0.4.0.1, base-4.6.0.1,
binary-0.5.1.1, rts-1.0, bytestring-0.10.0.2, containers-0.5.0.0,
deepseq-1.3.0.1, ghc-prim-0.3.0.0, integer-gmp-0.5.0.0, utf8-string-1
Haddock coverage:
93% ( 14 / 15) in 'projectname'
Warning: SHA1: could not find link destinations for:
GHC.Base.String Data.ByteString.Lazy.Internal.ByteString GHC.Word.Word32 GHC.Integer.Type.Integer GHC.Types.Int Data.Sequence.Seq
Run Code Online (Sandbox Code Playgroud)
现在我用谷歌搜索了一下,发现解决方案是尝试重新安装这些软件包haddock install array-0.4.0.1 base-4.6.0.1 binary-0.5.1.1 rts-1.0 bytestring-0.10.0.2 containers-0.5.0.0 deepseq-1.3.0.1 ghc-prim-0.3.0.0 integer-gmp-0.5.0.0 utf8-string-1 --enable-documentation,但失败了
cabal: Could not resolve dependencies:
rejecting: base-4.8.0.0, 4.7.0.2, 4.7.0.1, 4.7.0.0 …Run Code Online (Sandbox Code Playgroud) 我如何才能以最有效的方式替换Haskell中Text值中第一次出现的"substring"(实际上是Data.Text.Text)?
假设我有类似的功能
foo = 8 + f1
where f1 = 8 + 9
f2 = 8 + 10
Run Code Online (Sandbox Code Playgroud)
f1显然必须进行评估,但f2不一定要评估.会不会呢?我可以看到评估每个where表达式是一个性能问题.
我有一个参数解析器使用getOpt哪个很好,但我确实有一个问题.ReqArg在以下选项中使用 时:
Option ['c'] ["config"] (ReqArg (\f opts -> opts { configFile = f }) "FILE")
"use a custom configuration file"
Run Code Online (Sandbox Code Playgroud)
它是如何使用第二个参数(在这种情况下"FILE")?指定另一个字符串时,我没有遇到任何行为上的差异.
我想在Haskell中用字符串替换子字符串,而不使用外部库,如果可能的话,还要具有良好的性能.
我想过使用Data.Text替换函数,但我不想将整个程序移植到使用Text类型而不是Strings.将包装String成一个Text值,然后替换我想要的东西,然后将那个Text值解压缩到String很多的缓慢Strings?
我试图在haskell中实现fibonacci函数只是为了尝试语言,但我已经坚持只是编译我的程序.我有以下代码:
main = do
fib :: (Num a) => a -> a
fib 0 = 0
fib 1 = 1
fib x = fib (x - 1) + fib (x - 3)
fib 348
Run Code Online (Sandbox Code Playgroud)
我不知道我做错了什么.这是ghc在编译时的输出ghc --make fib.hs
[1 of 1] Compiling Main ( fib.hs, fib.o )
fib.hs:3:15: parse error on input `=´
Run Code Online (Sandbox Code Playgroud)
如果这是相关的,我使用的是Windows.
我编写了一个在haskell中执行SHA-1的程序,虽然它确实产生了哈希,但它们与其他SHA-1程序产生的哈希不匹配
示例:cat
hashes to:b5be86bc8bccfc24b01b093228ebb96fc92fa804但应该哈希到9d989e8d27dc9e0ec3389fc855f142c3d40f0c50
我的代码是:
(old code omitted)
Run Code Online (Sandbox Code Playgroud)
我不知道出了什么问题.有人能告诉我哪里弄错了吗?
编辑:
我修复了指出的东西,但它仍然无法正常工作.它正常工作直到内循环.我清理了代码,以便为内循环的功能都可以f1,f2而f3
cat现在有趣的哈希来ebe6c9fa1afa0ef5a0ca80bab251fd41cc29127e.
码:
import Data.Word
import Data.Bits
import Data.Char (ord, intToDigit)
import Data.Binary (encode, decode)
import Numeric (showHex, showIntAtBase)
import System.IO (stdin)
import Data.Sequence ((<|), (|>))
import qualified Data.Sequence as S
import qualified Data.ByteString.Lazy as B
type Quintuple32 = (Word32, Word32, Word32, Word32, Word32)
addQuintuple (a, b, c, d, e) (f, g, h, i, j) =
(a + …Run Code Online (Sandbox Code Playgroud)