question in urgent

4 views
Skip to first unread message

Xiyao Gong

unread,
Mar 6, 2010, 5:36:48 PM3/6/10
to proglang-course-2010
hej,
I have a question about the lab4.
suppose we have haskell code like
case 1
fun1 f x = x;
fun2 k = fun1 k 100;

case 2
fun1 f x = x;
k x = x;
fun2 = fun1 k 100;

How can my BNFC code know that what k is (a function or a variable) in
fun2. I mean in case 1 k is a variable but in case2 k is a function.
My code always regard k as a function but not a variable.
I define the application of function as
DFun. Exp3 ::= Ident [Exp] .
Is this ok or bad?
Thanks in advance.

Aarne Ranta

unread,
Mar 6, 2010, 5:43:35 PM3/6/10
to proglang-c...@googlegroups.com
The rule is that every identifier is a variable if it is in the scope of a lambda that binds it. For instance, in 

  e 

in 

  \k -> e

k is always a variable, even if it had been defined as a function as well. The recommended env in the lab takes care of this automatically: the funs are "on the bottom" of the env, and the lambdas are added "on the top" and hence have a priority when lookup is performed.

Regards

  Aarne.
Reply all
Reply to author
Forward
0 new messages