控制语句中的haskell解析错误(可能是不正确的缩进或括号不匹配)

时间:2016-05-30 08:24:59

标签: parsing haskell indentation

我正在尝试让某些东西起作用,这是为了游戏。我遇到了一个我无法追踪的解析错误。

getLineDir :: (Int, Int) -> Piece -> Board -> [Piece]
getLineDir (x,y) (Piece (x',y') player) board 
            | pieceAt(x'+ x, y'+ y) board == Nothing = []
            | if pieceAt(x'+ x, y'+ y) board == Just (Piece _ player') && isPlayer player (Piece _ player') == True then (Piece (x',y') player):[] else (Piece _ player'): getLineDir (x,y) (Piece (x'+x, y'+y) player) board

flippable :: [Piece] -> [Piece]

我收到的错误消息是:

  

解析错误(可能是错误的缩进或括号不匹配)

我在以“flippable”开头的行中得到解析错误,所以我猜测前一行有问题。

2 个答案:

答案 0 :(得分:1)

您不能将==Just (Piece _ player')这样的模式一起使用。与case一样,您需要正确的模式匹配。

getLineDir :: (Int, Int) -> Piece -> Board -> [Piece]
getLineDir (x,y) (Piece (x',y') player) board =
   case pieceAt (x'+ x, y'+ y) board of
   Nothing -> []
   Just piece@(Piece _ player')
     | isPlayer player piece -> [Piece (x',y') player]
     | otherwise -> piece : getLineDir (x,y) (Piece (x'+x, y'+y) player) board

可能Just piece@(Piece _ player')可以简单地替换为Just piece,因为之后你永远不需要player'

答案 1 :(得分:0)

以下情况如何?

public IEnumerable<User> users()
{
    var users = Userlist();
    return users.ToList();
}

public static List<User> Userlist()
{
    string strSQL = "";
    List<User> users = new List<User>();
    strSQL = "select USERID,USERNAME,PASSWORD from USERS";

    //if (Userlist().Count > 0)
    //{
    //    return Userlist();
    //}
    //else
    //{
    using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString))
    {
        using (var command = new SqlCommand(strSQL, connection))
        {
            connection.Open();
            using (var dataReader = command.ExecuteReader())
            {
                while (dataReader.Read())
                {
                    users.Add(new User { Id = Convert.ToInt32(dataReader["USERID"]), user = dataReader["USERNAME"].ToString(), password = Decrypt(dataReader["PASSWORD"].ToString()), estatus = true, RememberMe = true });
                }
            }
        }
    }
    return users;
    // }
}