相关疑难解决方法(0)

是否可以在规范化理论中输入`min`,如System-F或Constructions?

min下面的定义适用于两个教堂数量和返回至少大.每个数字都成为一个延续,将其pred传递给另一个,zig和zag,直到达到零.此外,每次调用时,其中一个数字会将f附加到结果中,因此,最后,您将获得(\ f x -> f (... (f (f x)) ...))右边的'f'的数量是第一个连续调用的次数.

min a b f x = (a_continuator b_continuator)
    a_continuator = (a (\ pred cont -> (cont pred)) (\ cont -> x))
    b_continuator = (b (\ pred cont -> (f (cont pred))) (\ cont -> x))
Run Code Online (Sandbox Code Playgroud)

似乎min无法在System-F上输入.例如,为了在GHC上运行它,我不得不使用unsafeCoerce两次:

import Unsafe.Coerce

(#)   = unsafeCoerce
min'  = (\ a b f x -> (a (\ p c -> (c # p)) (\ c -> x) (b …
Run Code Online (Sandbox Code Playgroud)

haskell types type-theory agda dependent-type

9
推荐指数
1
解决办法
226
查看次数

为什么Haskell不接受我的组合"zip"定义?

这是教科书的zip功能:

zip :: [a] -> [a] -> [(a,a)]
zip [] _ = []
zip _ [] = []
zip (x:xs) (y:ys) = (x,y) : zip xs ys
Run Code Online (Sandbox Code Playgroud)

我在#haskell上问过早期的"zip"可以单独使用"foldr"实现,没有递归,没有模式匹配.经过一番思考,我们注意到可以使用continuation消除递归:

zip' :: [a] -> [a] -> [(a,a)]
zip' = foldr cons nil
    where
        cons h t (y:ys) = (h,y) : (t ys)
        cons h t []     = []
        nil             = const []
Run Code Online (Sandbox Code Playgroud)

我们仍然留有模式匹配.在进行了一些神经元烘烤之后,我想出了一个我认为合乎逻辑的不完整答案:

zip :: [a] -> [a] -> [a]
zip a b = (zipper a) (zipper b) where
    zipper = foldr …
Run Code Online (Sandbox Code Playgroud)

haskell fold

8
推荐指数
1
解决办法
406
查看次数

如何在Morte中输入zipWith?

这是zipWithMorte中几乎有效的定义:

zipWith
  =  ? (u : *)
  -> ? (f : (u -> u -> u))
  -> ? (a : (#List u))
  -> ? (b : (#List u))
  -> ? (List : *)
  -> ? (cons : (u -> List -> List))
  -> ? (nil : List)
  -> ((? (A:*) -> ? (B:*) ->
  (a (B -> List)
    (? (h:u) -> ? (t : (B -> List) -> ? k : B -> (k h t)))
    (? (k:B) …
Run Code Online (Sandbox Code Playgroud)

haskell functional-programming agda dependent-type morte

3
推荐指数
1
解决办法
184
查看次数

如何修复我的代码中的错误('无法构造无限类型')以及如何使我的代码工作

基本上我正在尝试执行一个函数,在这个函数中给出一个列表和一个数字,你必须将列表拆分为与给定数字大小相同的列表,并且所有列表的最后一次拆分的长度都应该低于给定的数字

separa a xs = if length xs >= a then separaM a (drop a xs) ([take a xs]) else [xs]

separaM a xs yss = if length xs >= a then separaM a (drop a xs) (yss : (take a xs)) else separaM a [] (yss : xs)
separaM a [] yss = yss
Run Code Online (Sandbox Code Playgroud)

我希望3"comovais"的输出为["com","ova","is"]但是在我的程序中由于错误而没有输出

haskell list

0
推荐指数
1
解决办法
81
查看次数