- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
跟随 this post 中优秀答案的引领,我正在尝试获取 ArrowLoop
的工作示例不使用箭头符号。在我完全理解箭头在引擎盖下的工作原理之前,我对使用箭头符号感到不舒服。话虽如此,我已经构建了一个基于我对 Arrows 的(有限)理解的小程序应该可以工作。然而,它最终以可怕的 <<loop>>
结束。异常(exception):
module Main where
import Control.Wire
import FRP.Netwire
farr :: SimpleWire (Int, Float) (String, Float)
farr = let
fn :: Int -> Float -> ((String, Float), SimpleWire (Int, Float) (String, Float))
fn i f = (("f+i: " ++ (show (fromIntegral i + f)), f + 0.1), loopFn)
loopFn :: SimpleWire (Int, Float) (String, Float)
loopFn = mkSFN $ \(i, f) -> fn i f
in
mkSFN $ \(i, _) -> fn i 0.0
main :: IO ()
main = do
let sess = clockSession_ :: Session IO (Timed NominalDiffTime ())
(ts, sess2) <- stepSession sess
let wire = loop farr
(Right s, wire2) = runIdentity $ stepWire wire ts (Right 0)
putStrLn ("s: " ++ s)
(ts2, _) <- stepSession sess2
let (Right s2, _) = runIdentity $ stepWire wire2 ts (Right 1)
putStrLn ("s2: " ++ s2)
<<loop>>
当您不向循环提供初始值时,通常会出现异常。我不是用包含
fn i 0.0
的行完成的吗? ?输出不一致:
$ ./test
s: f+i: 0.0
test.exe: <<loop>>
最佳答案
主要的混淆点似乎是 ArrowLoop
之间的积分关系。和 mfix
.对于初学者,fix
是一个函数,finds the fixed point给定函数的:
fix :: (a -> a) -> a
fix f = let x = f x in x
mfix
是这个函数的 monadic 扩展,不出所料,它的类型签名是:
mfix :: (a -> m a) -> m a
ArrowLoop
有什么关系? ?嗯,
ArrowLoop
Netwire 运行的实例
mfix
在传递的电线的第二个参数上。换句话说,考虑
loop
的类型签名:
loop :: a (b, d) (c, d) -> a b c
ArrowLoop
的实例是:
instance MonadFix m => ArrowLoop (Wire s e m)
loop
与电线一起使用时的函数类型是:
loop :: MonadFix m => Wire s e m (b, d) (c, d) -> Wire s e m b c
loop
不采用
d
类型的初始参数,这意味着无法通过线路初始化任何类型的常规“循环”。从中获取值的唯一方法是继续应用输出作为输入,直到找到终止条件,这类似于
fix
作品。作为参数传递给
loop
的线路实际上从来没有超过一次,因为
stepWire
用不同的输入一遍又一遍地应用于同一条电线。只有当导线实际产生一个固定值时,函数才会步进并产生另一条导线(其行为方式与第一条相同)。
loop
应该可以工作,我将其命名为
semiLoop
:
semiLoop :: (Monad m, Monoid s, Monoid e) => c -> Wire s e m (a, c) (b, c) -> Wire s e m a b
semiLoop initialValue loopWire = let
runLoop :: (Monad m, Monoid s, Monoid e) =>
Wire s e m (a, c) (b, c) -> s -> a -> c -> m (Either e b, Wire s e m a b)
runLoop wire ts ipt x = do
(result, nextWire) <- stepWire wire ts (Right (ipt, x))
case result of
Left i -> return (Left i, mkEmpty)
Right (value, nextX) ->
return (Right value, mkGen $ \ts' ipt' -> runLoop nextWire ts' ipt' nextX)
in
mkGen $ \ts input -> runLoop loopWire ts input initialValue
delay
组合器对于防止
loop
至关重要组合子发散。
delay
简单地在使用
mfix
中的下一个值的懒惰之间创建一个单值缓冲区。上述循环的一部分。
semiLoop
的相同定义因此,以上是:
semiLoop :: (MonadFix m, Monoid s, Monoid e) =>
c -> Wire s e m (a, c) (b, c) -> Wire s e m a b
semiLoop initialValue loopWire = loop $ second (delay initialValue) >>> loopWire
关于haskell - 与 Netwire 一起使用时对 ArrowLoop 的误解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25131107/
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 4 年前。 Improve th
我有一组标题级别(1 到 6)。我正在使用 @for 循环,但我似乎无法弄清楚如何将它们分组而不是单独分组。 这是我正在使用的@for 循环: @for $i from 1 through 6 {
我在别处读到使用版本字符串到 网址 的 XML 模式通常是不好的做法 - 出于我理解的原因。 我想知道这个咒语在使用 Marklogic DB 时是否仍然适用?我的原因是命名空间和存储 XML Mar
下面是我的代码片段,它将多部分请求发布到服务器。根据某种条件,它决定只发布一个文件或同时发布两个文件。 // Based on some condition add 1 or 2 files to t
我尝试使用Collections.sort方法对类别数组列表进行排序,但没有成功。 这是我的代码: public class Categories implements Parcelable {
JSON: "ABCD": [ { "xyz": 3, "abc": 4, "info": { "MY_TITLE": "Hello World",
我正在尝试更新我的 MySQL 数据库服务器的一些变量;我在 Windows 10 64 位 笔记本电脑上运行 Maria 版本 10.3.12。我尝试更新位于此处的 my.ini 文件: C:\Pr
有一系列的 YouTube 视频,我想嵌入而不必每次都重写嵌入代码,所以使用了 stringWithFormat 来动态插入 URL: videoHTML = [NSString stringWith
如果客户端请求的域没有有效的 CA 签名证书,并且服务器不打算支持 HTTPS 但确实支持该域的 HTTP,那么在 Web 服务器中处理此问题的最佳方法是什么。请注意,服务器确实处理其他域上的 SSL
此时我们有一个在 Linux 和 weblogic 设置上运行的 Web 应用程序。有一个本地目录/home/doc 用于存储我们应用程序中使用的文件。 目前,我们通过wls:虚拟url映射和wls:
我一直在思考这个问题,但还没有想出任何稳定/优雅的想法。 我知道使用 MyISAM 表,您可以获得表 def 更新时间,但对于 InnoDB 则不然,我发现查看 .frm 文件以了解定义何时更新甚至不
我有一个 Ruby 散列,我正在将其转换为 to_json 并传递给 View 。然后 JavaScript 解析 JSON (JSON.parse) 并对其进行迭代,生成键值对。如何对散列进行排序,
我正在使用 org.json 库中可用的转换函数将 json 转换为 xml。这样做非常简单。 String xmlStr = XML.toString(new JSONObject(jsonStr)
我的 View 模型拥有一个非常简单的 recyclerview 适配器 当我尝试向它发送消息(进而调用 notifyDatasetChanged )时,它会抛出这样的异常 java.lang.Nul
我按以下方式设置了 GridView: 绑定(bind)到List在代码隐藏中(我正在使用我自己的自定义 BOL) HTML 页面上没有数据源对象 可对我选择的每一列进行排序(SortExpressi
假设我想测试用户是否能够填写表单来创建新项目。我需要访问的路由是:new_user_project_path(:user_id)。 所以,我的特征 rspec 现在看起来像这样: feature "U
我有一个 linux 机器,我在上面编译并安装了更新版本的 GCC (4.3.9),它位于/usr/lib 中。 我使用此编译器构建了一组库,并将其捆绑到 RPM 中,但是当我尝试安装该 RPM 时,
@DependsOn(value="userService") public class AuthcRealm implements Realm { @Autowired @Lazy(value=fa
我的团队最近更新了我的网站 www.uksoccershop.com,以使用 timthumb 显示图像缩略图。这已经成功完成,但是从 Google 图片中丢失 SEO 流量的问题迫在眉睫。恐怕 Go
我试图构建一个 kd 树来搜索一组点,但我对维基百科文章中“中位数”的使用感到困惑。为了便于使用,维基百科文章将构造kd-tree的伪代码表述为: function kdtree (list of p
我是一名优秀的程序员,十分优秀!