spec = describe "Router" $ do
let sampleRoutes = [( Tuple "/" "views/index.yaml" ),
( Tuple "/foo" "views/foo.yaml" ),
( Tuple "/bar" "views/bar.yaml" )]
it "should default to the first of the list" $ do
r <- fst <$> head sampleRoutes
fprint r
Run Code Online (Sandbox Code Playgroud)
以上抛出以下错误:
Error in declaration spec
Cannot unify Data.Maybe.Maybe with Control.Monad.Eff.Eff u4505.
Run Code Online (Sandbox Code Playgroud)
我相信这是因为它期望第二个参数是 type Eff,但是由于使用Maybe由head第二个参数引入的,最终变成了 type Maybe。
it :: forall e a. String -> Eff e a -> Eff (it :: It …Run Code Online (Sandbox Code Playgroud) 如何在 Pure-Script 中加载外部 JavaScript 文件?
外部导入语句都内联 javascript 代码,但我想从外部文件加载它们。
我正在使用 purescript-halogen 来构建一个类似电子表格的表格(类似于Handsontable)。如果您双击一个单元格,一个 html 输入元素将呈现为相应表格单元格的子元素(并且不会为所有其他单元格呈现此类元素)。
这对卤素非常有效,只是我不知道如何自动将焦点设置到新创建的输入元素。
我尝试了该autofocus属性,但这仅适用于双击的第一个单元格。JavaScript 的focus()方法是在新元素上调用该方法,但是我不知道在卤素中更新 DOM 后如何调用它。有任何想法吗?
我正在寻找有关编译器错误消息The value of xyz is undefined here, so reference is not allowed.以及 do-notation 的一些说明。我没有设法对这个例子进行足够的概括,我所能给出的只是我偶然发现这种行为的具体例子。对不起。
使用purescript-parsing,我想编写一个接受嵌套多行注释的解析器。为了简化示例,每个注释都以 开头(,以 结尾,)并且可以包含一个a或另一个注释。一些例子:(a)并((a))接受(),(a或被foo拒绝。
以下代码导致The value of comment is undefined here, so reference is not allowed.该行出错content <- string "a" <|> comment:
comment :: Parser String String
comment = do
open <- string "("
content <- commentContent
close <- string ")"
return $ open …Run Code Online (Sandbox Code Playgroud) 我试图理解为什么以下在Purescript中不起作用.我有一种感觉,它也可以由Haskell社区回答,因此我已经交叉列出了它.
一般要点是:
如果我有do块,我可以不投入一次性价值吗?在这个例子中,我试图print在一系列monadic计算中记录某些东西(类似于Haskell的).
main = do
a <- someAction1
b <- someAction2
_ <- log "here is a statement I want printed"
someAction3 a b
Run Code Online (Sandbox Code Playgroud)
具体来说,我有一个功能,它采取以下(从卤素示例模板项目)
data Query a = ToggleState a
eval :: Query ~> H.ComponentDSL State Query g
eval (Toggle next) = do
H.modify (\state -> state { isOn = not state.isOn })
_ <- log "updating the state!"
pure next
Run Code Online (Sandbox Code Playgroud)
在我看来,这应该像Haskell一样工作
barf :: IO Int
barf = do
_ <- print "Here I …Run Code Online (Sandbox Code Playgroud) 我在 Purescript 文件中定义了几种类型:
data Point = Point {
x :: Int,
y :: Int
}
data Rect = Rect {
upperLeft :: Point,
upperRight :: Point,
lowerLeft :: Point,
lowerRight :: Point
}
Run Code Online (Sandbox Code Playgroud)
现在我想定义一个函数来检查两个矩形是否重叠:
rectsOverlap :: Rect -> Rect -> Boolean
rectsOverlap r s = (r.upperLeft.x > s.lowerRight.x && r.upperLeft.y > s.lowerRight.y)
|| (r.upperLeft.x < s.lowerRight.x && r.upperLeft.y < s.lowerRight.y)
|| (r.lowerLeft.x > s.upperRight.x && r.lowerLeft.y > s.upperRight.y)
|| (r.lowerLeft.x < s.upperRight.x && r.lowerLeft.y < s.upperRight.y)
Run Code Online (Sandbox Code Playgroud)
但是,这会导致以下错误:
Could not match …Run Code Online (Sandbox Code Playgroud) 我可以在 JS 中使用 PureScript 类型吗?例如:
type SomeType = /*type declaration*/
func :: SomeType
func = /*type construction*/
Run Code Online (Sandbox Code Playgroud)
然后在 JS 中做这样的事情:
let a = module.func()
a instanceof module.SomeType === true
Run Code Online (Sandbox Code Playgroud)
如果没有,是否有任何 Haskellish 语言可以实现它(Elm、GHCJS、Idris?)?
我对 Purescript 很陌生,所以这可能是一个天真的问题。
我想编写一个 Purescript 函数,该函数从浏览器上的 HTML 输入元素读取输入并将一些输出写入另一个 HTML 输入元素。
使用普通的 Javascript,它就像document.getElementById('output').value = myFun(document.getElementById('input'));. 我如何只用 Purescript 做到这一点?
applicative do notation / adovs. applicative lift via <$>/ mapon the first argument的评估顺序似乎有所不同,而<*>/apply对于其余参数。
至少,这是我到目前为止所读到的内容,以及在下面显示的练习过程中所反映的内容。问题:
ado),尊重测试中的预购断言?可以在此处找到 PureScript by Example 书(第 7 章)中的练习:
3.(中)编写一个函数
traversePreOrder :: forall a m b. Applicative m => (a -> m b) -> Tree a -> m (Tree b)来执行树的前序遍历。[...] Applicative do notation (ado) 是编写此函数的最简单方法。
代数数据类型Tree:
data Tree a
= Leaf …Run Code Online (Sandbox Code Playgroud) 如果我有记录类型:
type Rec_ab = { a :: String, b :: Int }
Run Code Online (Sandbox Code Playgroud)
我可以从它的类型中得到有效扩展的{c :: Boolean}:{ a :: String, b :: Int, c :: Boolean }吗?
如果我有一行,我可以这样做:
Row_ab = ( a :: String, b :: Int )
Rec_abc = { c :: Boolean | Row_ab }
Run Code Online (Sandbox Code Playgroud)
但如果我有记录Rec_ab应该如何解决?我不知道从“记录”->“行”的方式。