小编D. *_*oso的帖子

尝试在同一节点中的两个嵌入式 Elm 应用程序之间切换失败

我正在尝试根据用户输入在 Elm 应用程序之间动态切换。

这两个应用程序都通过 js 文件进行转译elm make(例如:Foo.js 暴露模块 Foo 和 Bar.js 暴露模块 Bar)

两个按钮运行通常的“Elm.[Foo|Bar].init(node:document.querySelector('main')”,这样理论上我可以在渲染任一应用程序之间切换。

<html>
<head>
  <script src="[..]/foo.js"></script>
  <script src="[..]/bar.js"></script>
</head>
<body>
  <main></main>

  <input value="Foo" type="button" name="Foo" onclick="Elm.Foo.init({node:document.querySelector('main')});">
  <input value="Bar" type="button" name="Bar" onclick="Elm.Bar.init({node:document.querySelector('main')});">
</body>
</html>

Run Code Online (Sandbox Code Playgroud)

需要明确的是,两个应用程序应该交替接管该元素。

当我第一次点击其中一个按钮时,应用程序会正确呈现,但第二次单击会产生以下错误

Error: What node should I take over? In JavaScript I need something like:

    Elm.Main.init({
        node: document.getElementById("elm-node")
    })

You need to do this with any Browser.sandbox or Browser.element program.
Run Code Online (Sandbox Code Playgroud)

事实上,该元素在渲染第一个应用程序时以某种方式被删除。

我在文档中找不到任何提及此行为的信息,我想知道是否可以以任何方式防止这种情况发生,以及这是否是预期的行为。

提前致谢

elm

4
推荐指数
1
解决办法
378
查看次数

<*>如何使用Function Applicative?

我试图弄清楚lambda演算为什么以下代码的函数结果

(,) <$> (+1) <*> (+1)
Run Code Online (Sandbox Code Playgroud)

类型为Num a => a - >(a,a)而不是Num a => a - > a - >(a,a)

这就是我所拥有的,我做了一些可怕的错误,或者<*>只是这样连接?

( \x, y -> (,) x y ) <$> ( \x -> x + 1 ) <*> ( \x -> x + 1 )

-- fmap applies first

(\x y -> (,) ((+1) x) y ) <*> ( \x -> x + 1 ) -- substituted the lambda with (+1) for better clarity

-- then goes apply

( \x …
Run Code Online (Sandbox Code Playgroud)

haskell applicative reader

2
推荐指数
1
解决办法
101
查看次数

标签 统计

applicative ×1

elm ×1

haskell ×1

reader ×1