Should this be possible?

2 views
Skip to first unread message

Per Reimers

unread,
Mar 9, 2011, 1:01:50 PM3/9/11
to proglang-c...@googlegroups.com
If you run this program:

f x = y
main = (\y -> f 0) 1

Is it valid, returning 1?

per odlund

unread,
Mar 9, 2011, 5:13:55 PM3/9/11
to proglang-c...@googlegroups.com
2011/3/9 Per Reimers <per.r...@gmail.com>

No it shouldn't, it's types doesn't match.
If you mean:
rconst x y = y       -- a (evil) cusin of const
main = (\y -> rconst 0) 1

I don't know what the specs says but it shouldn't be that hard to get it to work.

Per Reimers

unread,
Mar 9, 2011, 5:43:46 PM3/9/11
to proglang-c...@googlegroups.com
2011/3/9 per odlund <per.o...@gmail.com>

Ah, yes.
What I actually was thinking about was: is it allowed to parse it as stated?
The reason is that the name 'y' is bound when executing f, so it takes that value and returns it.
My example can be minimized further:

f = y
main = (\y -> f) 2

My program does not typecheck on beforehand, because that is not required...

per odlund

unread,
Mar 9, 2011, 6:06:23 PM3/9/11
to proglang-c...@googlegroups.com


2011/3/9 Per Reimers <per.r...@gmail.com>
The problem is that y is not i scope in f (f is a constant and not a abstraction).
f = 1

main = (\y -> f) 2
should always return 1.

if you want f to return 2 you have done something wrong with the substitution.

Per Reimers

unread,
Mar 9, 2011, 6:28:29 PM3/9/11
to proglang-c...@googlegroups.com
2011/3/10 per odlund <per.o...@gmail.com>

I see the problem but I don't know what it is...
Two questions:
When is substitutions needed?
And why is
  f = y
  main = (\y -> f) 2
not valid when
  main = (\y -> y) 2
is?

per odlund

unread,
Mar 9, 2011, 9:39:17 PM3/9/11
to proglang-c...@googlegroups.com


2011/3/10 Per Reimers <per.r...@gmail.com>
f = y , is not valid if not y is defined as a constant, making f a constant. But in the scope I have seen I don't see a y in the global map.

if y is defined this is (might do some step wrong,kinda late) do it.
y = 3

f = y
main = (\y -> f) 2
main = (f) [y := 2]
main = f [f := y]
main = y [f := 3]
main = 3

Even if f would take an y as an argument, that wouldn't change much, they are not the y and we should do a alpha-convertion to treat them differently. Even now we have 2 variables called y but they are not the same.
since f is a constant [y := 2] wont do much. I think you need to look over the rules one more time.
Reply all
Reply to author
Forward
0 new messages