这是我的代码:
select_where_true :: (Double -> Bool) -> [Double] -> [Double]
select_where_true is_neg [a] = case [a] of
[] -> []
x:xs -> is_neg x
|(is_neg x) == False = []
|(is_neg x) == True = x ++ (select_where_true is_neg xs)
is_neg :: Double -> Bool
is_neg x = x < 0
Run Code Online (Sandbox Code Playgroud)
这是错误消息:
[1 of 1] Compiling Main ( test.hs, interpreted )
test.hs:5:18: parse error on input `|'
Failed, modules loaded: none.
Run Code Online (Sandbox Code Playgroud)
有人喜欢告诉我我的代码有什么问题吗?
感谢任何能给我一些建议的人.
当我尝试编译它时,以下do块会抛出错误"输入`conn'上的解析错误".我尝试过if-then-else语句的许多不同配置无济于事.在添加条件之前数据库逻辑工作,所以没有问题.我在其他地方有太多行吗?有没有办法解决这个问题而不完全修改逻辑?
main = do
contents <- BL.getContents
let myData = decode contents :: Maybe Data
if maybe True (\x -> result x /= "success") myData
then error ("JSON download failed")
else let myTrades = process myData
conn <- connectSqlite3 "trades.db"
insert <- DB.prepare conn "INSERT INTO trades VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);"
DB.executeMany insert $ map (\xs -> map DB.toSql xs) myTrades
DB.commit conn
DB.disconnect conn
Run Code Online (Sandbox Code Playgroud) 我试图编写一个带有列表对的函数,并交换对元素
inverse :: [(a,b)] -> [(b,a)]
inverse [] = []
inverse (x,y):xs = (y:x): inverse xs
Run Code Online (Sandbox Code Playgroud)
我通过Prelude加载了这个函数,它给了我以下错误:
mydefs.hs:11:1:模式中的解析错误:反向
这是第11行, inverse (x,y):xs = (y:x): inverse xs
我正在写一个程序来帮助我的弟弟学习加法.我没有编写IO程序的经验,而且我遇到了这个解析错误:
MyCode.hs:6:25:
Parse error in pattern: show
Possibly caused by a missing 'do'?
Run Code Online (Sandbox Code Playgroud)
代码:
mathExercise times (a,b) =
if times<=0
then return ()
else do let x = randInt a
let y = randInt b
putStr (show x ++ " + "++ show y++ " = ")
ans <- getInt
if (ans==x+y)
then do print True
mathExercise (times-1) (a,b)
else do print False
Run Code Online (Sandbox Code Playgroud) 我有以下代码,旨在从表达式的评估中取出重复,m并替换开头的双重se
exec (Assign s e) m = assign s (eval e m) m
where assign _ _ [] = error ("undef var " ++ s)
assign s v (x:xs)
| fst x == s = if sameKind v (fst x)
then (fst x,v):xs
else error "type error in assign"
| otherwise = x:(assign s v xs)
where sameKind (VInt a) (VInt b) = True
sameKind (VBool a) (VBool b) = True
sameKind _ _ = False …Run Code Online (Sandbox Code Playgroud) 我的Web.config文件突然出现以下错误,我不明白这意味着什么:
分析器错误消息:属性"connectionStringName"缺失或为空.
Line 24: <providers>
Line 25: <clear />
Line 26: <add name="SMDPortalMembershipProvider" type="SMDPortalMembershipProvider" />
Line 27: </providers>
Line 28: </membership>
Run Code Online (Sandbox Code Playgroud)
源文件:c:\ inetpub\wwwroot\web.config行:26
版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.272
这是我的配置文件:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="UODOTNET, Version=2.2.5.7444,
Culture=neutral, PublicKeyToken=335F3FBD4BE82339"/>
<add assembly="System.Core, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="Default.aspx" timeout="2880" /> …Run Code Online (Sandbox Code Playgroud) 我刚刚开始使用Haskell,我无法理解一件事 - 为什么这样的东西不起作用?
fun f = f * f
main =
do
foo <- getLine
bar <- getLine
print (fun 4)
Run Code Online (Sandbox Code Playgroud)
我一直收到来自ghc的"输入`print'的解析错误".但对我来说更神秘的是它在移除foo < - getLine和bar < - getLine后起作用.有任何想法吗?
下面的代码被编程来决定Haskell中的纸岩和剪刀的结果,但是终端给出了错误
data Move = Paper | Rock | Scissors
deriving (Eq, Show)
data Result = Win | Draw | Loose
deriving (Eq, Show)
beats :: Move -> Move
beats move = case move of
Paper -> Scissors
Rock -> Paper
Scissors -> Rock
score :: Move -> Move -> Result
score this_move opposing_move
| this_move == beats opposing_move = Win
| this_move == opposing_move = Draw
| otherwise = Loose
Run Code Online (Sandbox Code Playgroud)
这是来自终端的错误消息
[1 of 1] Compiling Main ( test.hs, interpreted ) …Run Code Online (Sandbox Code Playgroud) 我有一个语法显然是错误的,因为解析一个简单的文件会产生奇怪的错误信息.
我尽可能地简化了以下语法而没有改变错误(如果你删除'this'了ANTLRWorks的树gui输出,那么int样本文件的标记会有不同的颜色,尽管结构看起来是相同的).
grammar DepClsJ_no_java_debug;
module : ( methodDecl )* ;
methodDecl : pathType Identifier '()' block ;
pathType : Identifier | 'this' ;
block : '{'
( localDecl ';' )*
( statement )*
( expr )?
'}' ;
localDecl : pathType Identifier ( '=' expr )?;
statement : block | expr ';' ;
expr : dotExpr ( '=' dotExpr )* ; dotExpr : Identifier ( '.' Identifier )* ;
Identifier : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')* ;
Run Code Online (Sandbox Code Playgroud)
演示代码:
void …Run Code Online (Sandbox Code Playgroud) 我是Haskell的初学者,想要开始解决它的问题,所以我试图解决第一个SPOJ问题(问题代码:TEST)."问题"是读取行并打印它们直到"42"出现.
main = do input <- getLine
if input == "42" then putStr ""
else do putStrLn input
main
Run Code Online (Sandbox Code Playgroud)
我的解决方案非常简单,但输入'if'时出现解析错误.当我在开头和else语句中将'main'更改为'main2'时,一切正常.为什么'if'上有解析错误?
parse-error ×10
haskell ×8
antlr ×1
antlr4 ×1
asp.net ×1
c# ×1
conditional ×1
grammar ×1
guard ×1
if-statement ×1
io ×1
list ×1