pdm*_*ean 3 haskell wolfram-mathematica list infinite
我可以看到循环如何用于实现重复列表(例如[0,9,0,9,...],10/11的十进制扩展),但是如何实现一个具有一些初始元素的循环它可以解决重复模式(例如[3,1,4,2,8,5,7,1,4,2,8,5,7,...],22/7的十进制扩展)?我希望这样的结构能够很好地适应折叠等.
我特别感兴趣的是表示小数和连续分数,其中列表分别仅包含数字或数字,但是具有更一般类型的列表也是有意义的,例如数字对.
Mathematica实现了重复分数(RealDigits和FromDigits)和重复连续分数(ContinuedFraction和FromContinuedFraction):
ContinuedFraction[Sqrt[13]] = {3,{1,1,1,1,6}}
Run Code Online (Sandbox Code Playgroud)
和
RealDigits[22/7] = {{3,{1,2,8,5,7}},1}
Run Code Online (Sandbox Code Playgroud)
类似的问题在这里:https://mathematica.stackexchange.com/questions/21998/building-a-continued-fraction但结果似乎非常特别,我希望在Haskell中有更干净的东西.
为什么不在前面添加一些东西cycle呢?
3 : cycle [1, 4, 2, 8, 5, 7]
Run Code Online (Sandbox Code Playgroud)
而"循环"链表是尾部指向头部的链表,而这是一个链表,其中一个循环指向列表的中间,如下所示:
let x = [1, 4, 2, 8, 5, 7] ++ x in 3 : x
3 : (let x = 1 : 4 : 2 : 8 : 5 : 7 : x in x)
Run Code Online (Sandbox Code Playgroud)