如何在刺猬中定义生成一定长度列表的生成器?

问题描述

我尝试在f#刺猬中创建一个整数列表。该列表应包含10到20个元素,并包含0到5之间的整数。

Gen.list (Range.linear 10 20) (Gen.int <| Range.constant 0 5) |> Gen.printSample

引发异常:

=== Outcome ===
[5; 5; 2; 2; 0; 2; 3; 1; 1; 4]
=== Shrinks ===
> System.ArgumentException: The index is outside the legal range.
count = 9,distance past the list = 9
Parameter name: count
   at Microsoft.FSharp.Core.DetailedExceptions.invalidArgOutOfRange[?](String arg,Int32 index,String text,Int32 bound) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\local.fs:line 57
   at Microsoft.FSharp.Collections.ListModule.loop@474-29[a](Int32 count,Int32 i,FSharpList`1 lst) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\list.fs:line 477
   at Hedgehog.Gen.atLeast[a](Int32 n,FSharpList`1 xs)
   at Microsoft.FSharp.Collections.Internal.IEnumerator.next@193[T](FSharpFunc`2 f,IEnumerator`1 e,FSharpRef`1 started,Unit unitvar0) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\seq.fs:line 194
   at Microsoft.FSharp.Collections.Internal.IEnumerator.filter@188.System-Collections-IEnumerator-MoveNext() in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\seq.fs:line 196
   at Microsoft.FSharp.Collections.Internal.IEnumerator.map@75.DoMoveNext(b& curr) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\seq.fs:line 77
   at Microsoft.FSharp.Collections.Internal.IEnumerator.MapEnumerator`1.System-Collections-IEnumerator-MoveNext() in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\seq.fs:line 64
   at Hedgehog.Gen.PrintSample[a](Gen`1 g)
   at <StartupCode$FSI_0044>.$FSI_0044.main@()

因此,通常生成器会产生正确的结果,但是收缩逻辑会出现问题。这是一个错误吗?我做错了吗?我是否错过了解释此问题的文档?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)