随笔-341  评论-2670  文章-0  trackbacks-0
    有了Expected语法之后总是要实验一下的。现在给出一个非完整函数eq的声明,并用一个列表查找函数使用eq。已知代码如下:
 1 module main
 2 import system
 3 import sysutils
 4 import list
 5 
 6 func eq T :: T -> T -> bool expected
 7 
 8 def exists e xs =
 9     select xs of
10         case list x tail : if(eq e x) true (exists e tail)
11         case empty : false
12     end
13 
14 def eq a b = iequ a b
15 
16 def eq a b = fequ a b
17 
18 def main score = if (flt score 60.0"fail" "pass"
19 
20 def ints = list 1 (list 2 (list 3 empty))
21 def floats = list 1.0 (list 2.0 (list 3.0 empty))
22 def chars = "vczh"
23 
24 def main2 = exists 0 ints
25 def main3 = exists 0.0 floats
26 def main4 = exists 'a' chars

    注意最后一行。由于exists在这里接受字符,但是不存在接受字符的eq,因此输出错误:
1 生成符号表时发生错误
2 错误[1]    模块:main    行号:10
3 信息:符号"eq"无法匹配到函数,类型:(system.char -> (system.char -> system.bool))。

    如果我们把最后一行去掉,则会产生正确的结果。注意exists的两个实例所对应的eq是不同的:
  1 【Code Unit main】
  2     module main::main
  3     import list
  4     import system
  5     import sysutils
  6     func eq T :: (<T> -> (<T> -> system.bool)) expected
  7     func chars :: (system.list system.char) codefrom 7
  8     func eq :: (system.int -> (system.int -> system.bool)) codefrom 2
  9     func eq :: (system.float -> (system.float -> system.bool)) codefrom 3
 10     func exists T1 :: (<T1> -> ((system.list <T1>-> system.bool)) codefrom 1
 11     func floats :: (system.list system.float) codefrom 6
 12     func ints :: (system.list system.int) codefrom 5
 13     func main :: (system.float -> (system.list system.char)) codefrom 4
 14     func main2 :: system.bool codefrom 8
 15     func main3 :: system.bool codefrom 9
 16 
 17 【Assembly Unit main】
 18 
 19     [Information]
 20         Name             : main
 21         Function Count   : 9
 22         Slot Count       : 10
 23 
 24     [Function]
 25         Function Name    : chars
 26         Unique Name      : main::chars::#7
 27         Owner Unit       : main
 28         Level            : 0
 29         External Command : 
 30         Instance         : main::chars::#7::(system.list system.char)
 31 
 32     [Function]
 33         Function Name    : eq
 34         Unique Name      : main::eq::#2
 35         Owner Unit       : main
 36         Level            : 0
 37         External Command : 
 38         Instance         : main::eq::#2::(system.int -> (system.int -> system.bool))
 39 
 40     [Function]
 41         Function Name    : eq
 42         Unique Name      : main::eq::#3
 43         Owner Unit       : main
 44         Level            : 0
 45         External Command : 
 46         Instance         : main::eq::#3::(system.float -> (system.float -> system.bool))
 47 
 48     [Function]
 49         Function Name    : exists
 50         Unique Name      : main::exists::#1
 51         Owner Unit       : main
 52         Level            : 0
 53         External Command : 
 54         Instance         : <NULL>
 55 
 56     [Function]
 57         Function Name    : floats
 58         Unique Name      : main::floats::#6
 59         Owner Unit       : main
 60         Level            : 0
 61         External Command : 
 62         Instance         : main::floats::#6::(system.list system.float)
 63 
 64     [Function]
 65         Function Name    : ints
 66         Unique Name      : main::ints::#5
 67         Owner Unit       : main
 68         Level            : 0
 69         External Command : 
 70         Instance         : main::ints::#5::(system.list system.int)
 71 
 72     [Function]
 73         Function Name    : main2
 74         Unique Name      : main::main2::#8
 75         Owner Unit       : main
 76         Level            : 0
 77         External Command : 
 78         Instance         : main::main2::#8::system.bool
 79 
 80     [Function]
 81         Function Name    : main3
 82         Unique Name      : main::main3::#9
 83         Owner Unit       : main
 84         Level            : 0
 85         External Command : 
 86         Instance         : main::main3::#9::system.bool
 87 
 88     [Function]
 89         Function Name    : main
 90         Unique Name      : main::main::#4
 91         Owner Unit       : main
 92         Level            : 0
 93         External Command : 
 94         Instance         : main::main::#4::(system.float -> (system.list system.char))
 95 
 96     [Slot Item]
 97         Unique Name      : main::chars::#7::(system.list system.char)
 98         Parent Slot      : <NULL>
 99         Owner Function   : main::chars::#7
100 
101     [Slot Item]
102         Unique Name      : main::eq::#2::(system.int -> (system.int -> system.bool))
103         Parent Slot      : <NULL>
104         Owner Function   : main::eq::#2
105             3 = system::iequ::$kernelfp::iequ::(system.int -> (system.int -> system.bool))
106 
107     [Slot Item]
108         Unique Name      : main::eq::#3::(system.float -> (system.float -> system.bool))
109         Parent Slot      : <NULL>
110         Owner Function   : main::eq::#3
111             4 = system::fequ::$kernelfp::fequ::(system.float -> (system.float -> system.bool))
112 
113     [Slot Item]
114         Unique Name      : main::exists::#1::(system.float -> ((system.list system.float-> system.bool))
115         Parent Slot      : <NULL>
116         Owner Function   : main::exists::#1
117             0 = sysutils::if::#9::(system.bool -> (system.bool -> (system.bool -> system.bool)))
118             1 = main::eq::#3::(system.float -> (system.float -> system.bool))
119             2 = main::exists::#1::(system.float -> ((system.list system.float-> system.bool))
120 
121     [Slot Item]
122         Unique Name      : main::exists::#1::(system.int -> ((system.list system.int-> system.bool))
123         Parent Slot      : <NULL>
124         Owner Function   : main::exists::#1
125             0 = sysutils::if::#9::(system.bool -> (system.bool -> (system.bool -> system.bool)))
126             1 = main::eq::#2::(system.int -> (system.int -> system.bool))
127             2 = main::exists::#1::(system.int -> ((system.list system.int-> system.bool))
128 
129     [Slot Item]
130         Unique Name      : main::floats::#6::(system.list system.float)
131         Parent Slot      : <NULL>
132         Owner Function   : main::floats::#6
133 
134     [Slot Item]
135         Unique Name      : main::ints::#5::(system.list system.int)
136         Parent Slot      : <NULL>
137         Owner Function   : main::ints::#5
138 
139     [Slot Item]
140         Unique Name      : main::main2::#8::system.bool
141         Parent Slot      : <NULL>
142         Owner Function   : main::main2::#8
143             7 = main::exists::#1::(system.int -> ((system.list system.int-> system.bool))
144             8 = main::ints::#5::(system.list system.int)
145 
146     [Slot Item]
147         Unique Name      : main::main3::#9::system.bool
148         Parent Slot      : <NULL>
149         Owner Function   : main::main3::#9
150             9 = main::exists::#1::(system.float -> ((system.list system.float-> system.bool))
151             10 = main::floats::#6::(system.list system.float)
152 
153     [Slot Item]
154         Unique Name      : main::main::#4::(system.float -> (system.list system.char))
155         Parent Slot      : <NULL>
156         Owner Function   : main::main::#4
157             5 = sysutils::if::#9::(system.bool -> ((system.list system.char-> ((system.list system.char-> (system.list system.char))))
158             6 = system::flt::$kernelfp::flt::(system.float -> (system.float -> system.bool))
posted on 2008-11-02 07:36 陈梓瀚(vczh) 阅读(1499) 评论(0)  编辑 收藏 引用 所属分类: 脚本技术

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理