一个玩具的例子,但仍令人沮丧:
numberMapper:: IO ()
numberMapper = do codes <- forM [1 .. 4] (\num ->
do putStrLn $ "Enter a code for " ++ show num
code <- getLine
return code)
let numberCodes = zip [1 .. 4] codes
in forM numberCodes (\(num,code) ->
putStrLn $ "Got code " ++ show code ++ " for " ++ show num)
Run Code Online (Sandbox Code Playgroud)
ghci告诉我,我有一个Parse error in pattern: putStrLn,我无法弄清楚为什么它不能解析.
我正在关注一个关于在Angular中实现Drag&Drop的很棒的教程,我最初在这个StackOverflow答案中找到了这个链接到作者的博客和GitHub代码.
当我实现它并在我的项目中测试它时,我得到了错误:
[$parse:isecdom] Referencing DOM nodes in Angular expressions is disallowed! Expression: dropped(dragEl, dropEl)
Run Code Online (Sandbox Code Playgroud)
根据Angular Docs,问题在于我引用了一个将DOM对象作为DOM属性中的参数的函数 - 它发生在这一行:
<div x-lvl-drop-target='true' x-on-drop='dropped(dragEl, dropEl)'>drop zone</div>
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,该on-drop属性将此dropped函数(在我的控制器中定义)传递给指令lvlDropTarget(在下面发布),该指令调用它来执行用户执行的拖放操作.我喜欢这种设计,因为它使该指令可以在同一个应用程序中重复使用许多不同的拖放可能性.实际上,我只需要在我的控制器中定义一个不同的函数,并通过on-drop属性将它传递给指令.
然而,不幸的是,这似乎被Angular击落了.有没有人有任何其他如何实现相同的设计和功能,但在某种程度上Angular更好吗?
这是lvlDropTarget指令
module.directive('lvlDropTarget', ['$rootScope', 'uuid',
function ($rootScope, uuid) {
return {
restrict: 'A',
scope: {
onDrop: '&'
},
link: function (scope, el, attrs, controller) {
var id = angular.element(el).attr("id");
if (!id) {
id = uuid.new()
angular.element(el).attr("id", id);
}
el.bind("dragover", function (e) …Run Code Online (Sandbox Code Playgroud) 我想在Haskell中将Maybe Int转换为Int,如下所示:
convert :: Maybe Int -> Int
convert mx = case mx of
Just x -> x
Nothing -> error "error message"
Run Code Online (Sandbox Code Playgroud)
当我编译它时,Haskell告诉我:parse error on input 'Nothing'.
我需要这个,因为我想从Data.List模块中使用elem.Index函数获取列表中元素的索引,然后在take函数上使用此索引.我的问题是elemIndex返回a Maybe Int,但take需要一个Int.
我收到此错误:"PHP Parse错误:语法错误,第66行/ var/www/vhosts/...中的意外T_VARIABLE"
这是我的代码:
function combine($charArr, $k) {
$currentsize = sizeof($charArr);
static $combs = array();
static $originalsize = $currentsize; ###### <-- LINE 66 ######
static $firstcall = true;
if ($originalsize >= $k) {
# Get the First Combination
$comb = '';
if ($firstcall) { //if this is first call
for ($i = $originalsize-$k; $i < $originalsize; $i++) {
$comb .= $charArr[$i];
}
$combs[] = $comb; //append the first combo to the output array
$firstcall = false; //we only want to …Run Code Online (Sandbox Code Playgroud) 我写了这段代码:
addNums key num = add [] key num
where add res a:as b:bs
| a == [] = res
| otherwise = add res:(a+b) as bs
Run Code Online (Sandbox Code Playgroud)
在第3行,口译员说:
解析错误(可能是错误的缩进)
我找不到任何错误,既没有代码也没有缩进.我为每个标签放了四个空格.
注解:
即使这不编译:
addNums key num = add [] key num
where add res a:as b:bs
| a == [] = res
| otherwise = add res:(a+b) as bs
Run Code Online (Sandbox Code Playgroud)
第2行:
模式中的解析错误:添加
我正在尝试创建一个允许用户输入字符串列表的函数.该函数采用长度并允许用户输入长度为1的行.然后检查每一行以确保它与原始行的长度相同.但是,我遇到了一些问题,我找不到解决办法.
问题是我可以输入多于count-1行,并且长度没有像我预期的那样计算..例如,如果我输入["12","13"]然后["121","13" ]给出了错误,虽然长度相同!
read :: IO [Line]
read = do
line <- getLine
let count = length line
lines <- replicateM (count-1) $ do
line <- getLine
if length line /= count
then fail "too long or too short"
else return line
return $ line : lines
Run Code Online (Sandbox Code Playgroud)
Line的类型为String.
readLn给出了解析错误.
我刚刚编写了我的第一个Haskell程序,但是有一个我无法理解的错误.我认为这是正确的,因为我只是像书中的例子那样写它.有人可以帮帮我吗?
main = do
putStrLn "Hello, what's your name?"
name <- getLine
putStrLn ("Hey" ++ name ++ ", nice to meet you!")
Run Code Online (Sandbox Code Playgroud)
错误消息是:
输入'putStrLn'解析错误
它很奇怪.
我正在尝试使用Sequences来提高性能.在定义下面的函数时,我尝试在模式修补上下文中使用"三角形"运算符.
import qualified Data.Sequence as S
cleanField :: S.Seq Char -> S.Seq Char
cleanField ((S.<|) ' ' xs) = cleanField xs
cleanField ((S.|>) xs ' ') = cleanField xs
cleanField xs = xs
Run Code Online (Sandbox Code Playgroud)
GHC 7.4.1说:
seq.hs:4:13: Parse error in pattern: (S.<|)
Run Code Online (Sandbox Code Playgroud)
我可以不在模式匹配中使用三角形运算符(<|,|>)吗?
如果是这样,为什么我可以:在模式匹配中使用cons()运算符而不是三角形运算符?
我需要使用HttpClient来做一个POST json字符串.以下将是我的代码.从另一端,Json被映射到一个对象.
HttpClient client = HttpClientBuilder.create().build();
HttpPost post = new HttpPost(url);
String jsonData = "{ \"provider\" : null , \"password\" : \"a\", \"userid\" : \"mlpdemo\\mlpdemoins\" }";
post.setEntity(new ByteArrayEntity( jsonData.toString().getBytes("UTF8")));
HttpResponse response = client.execute(post);
Run Code Online (Sandbox Code Playgroud)
这里所有其他人都正确映射期望userId.这里的问题是反斜杠(mlpdemo\mlpdemins).我猜.如果我发送一个字符串作为用户ID,它将被映射而没有任何问题.例如:-
String jsonData = "{ \"provider\" : null , \"password\" : \"a\", \"userid\" : \"mlpdemoins\" }";
Run Code Online (Sandbox Code Playgroud)
这有效.
但是我需要这个(mlpdemo\mlpdemins)通过POSt发送.请帮帮我.
String jsonData = "{ \"provider\" : null , \"password\" : \"a\", \"userid\" : \"mlpdemo\\mlpdemoins\" }";
Run Code Online (Sandbox Code Playgroud)
这是我得到的例外.
com.fasterxml.jackson.core.JsonParseException: Unrecognized character escape 'm' (code 109)
at [Source: …Run Code Online (Sandbox Code Playgroud) 这是我的代码:
connected :: [(Integer,Integer)] -> Bool
connected [] = True
connected [(_,_)] = True
connected (a,b):(c,d):xs
| a > c = False
|otherwise = connected (c,d):xs
Run Code Online (Sandbox Code Playgroud)
当我加载它GHCi它显示
error: parse error in pattern: connected
我在哪里弄错了?
parse-error ×10
haskell ×7
angularjs ×1
dom ×1
http-post ×1
indentation ×1
io ×1
jackson ×1
java ×1
json ×1
maybe ×1
php ×1
replicate ×1
sequence ×1
syntax-error ×1