语法错误:插入LPAREN

时间:2017-12-24 07:43:53

标签: sml

这是我第一次使用sml。

我不明白这种语法有什么问题:

 fun merge (l1 : int list , l2 : int list) : int list = 
  if ([] , l2) then l2
  else if (l1 , []) then l1
    else (x :: xs , y :: ys) 
        if x < y then x :: (merge (xs , l2))
           else y :: (merge (l1 , ys)));

请帮忙

1 个答案:

答案 0 :(得分:1)

问题是/** * Definition for a point. * struct Point { * int x; * int y; * Point() : x(0), y(0) {} * Point(int a, int b) : x(a), y(b) {} * }; */ class Solution { private: Point ori; class Comparator { public: // calculate the euclidean distance between p and ori int distance(Point p) { return pow(p.x-ori.x, 2) + pow(p.y-ori.y, 2); } // overload the comparator (), the nearest point to // origin comes to the first bool operator() (Point l, Point r) { if (distance(l) > distance(r)) { return true; } } }; public: /* * @param points: a list of points * @param origin: a point */ void mainFunc(vector<Point> points, Point origin) { ori = origin; priority_queue<Point, vector<Point>, Comparator> pq; for (int i = 0; i < points.size(); i++) { pq.push(points[i]); } } }; / if / then语法不用于模式匹配。 (你已经融合了两种不相关的语法。)

因此,例如,else不起作用,因为if ([] , l2)表达式中的条件需要if类型,而bool则不需要。{/ p >

相反,你想写:

([], l2)