小编Ale*_*kov的帖子

创建一个允许类型在每次重复函数调用后更改的折叠,以便在没有递归的情况下调用函数n次

我试图使用定义的dfold 这里

dfold 
    :: KnownNat k    
    => Proxy (p :: TyFun Nat * -> *)    
    -> (forall l. SNat l -> a -> (p @@ l) -> p @@ (l + 1))  
    -> (p @@ 0) 
    -> Vec k a  
    -> p @@ k
Run Code Online (Sandbox Code Playgroud)

基本上它是一个折叠,允许您在每个循环后返回一个新类型.

我试图概括这个项目中定义的bitonicSort:https: //github.com/adamwalker/clash-utils/blob/master/src/Clash/Sort.hs

我有两个函数对dfold生成的类型很重要:

bitonicSort
    :: forall n a. (KnownNat n, Ord a)
    => (Vec n a -> Vec n a)             -- ^ The recursive step
    -> (Vec (2 * n) a …
Run Code Online (Sandbox Code Playgroud)

haskell type-systems clash type-level-computation

19
推荐指数
1
解决办法
488
查看次数

如何在Haskell转换过程中保留原生循环列表结构?

我正在使用"打结"技术研究Haskell中的图形式事物处理.我想,循环列表只是一种无限列表内部实现,所以在理想世界中我们不应该关心subj.但它可能会对计算复杂性产生巨大影响,请考虑具有循环世界的一维元胞自动机示例:

ribbon = let x = 0 : y
             y = 1 : x
         in  x

update_cycle :: Num a => [a] -> [a]
update_cycle lst@(_:xs) = ( f lst : update_cycle xs)
update_cycle []         = error "infinite cycle assumed"

f :: Num a => [a] -> a           --  some arbitrary list reduction
f (x:(y:_)) = traceShow "f called" $ x - y
Run Code Online (Sandbox Code Playgroud)

这是一个只有两个单元格的循环.让我们迈出一步:

*Main> take 2 $ update_cycle ribbon
[-1,1]
"f called"
"f called"
Run Code Online (Sandbox Code Playgroud)

多数民众赞成,现在有两个步骤:

*Main> take 2 $ …
Run Code Online (Sandbox Code Playgroud)

haskell graph time-complexity tying-the-knot cyclic-dependency

5
推荐指数
0
解决办法
148
查看次数