Commit 8357c5e44c76ec961b7c4ff740028083e1d4927d

  • avatar
  • Antti-Juhani Kaijanaho <antti-juhani @kaij…aho.fi> (Committer)
  • Fri Nov 16 18:55:04 EET 2012
  • avatar
  • Antti-Juhani Kaijanaho <antti-juhani @kaij…aho.fi> (Author)
  • Fri Nov 16 18:55:04 EET 2012
Evaluate the component before performing the projection

As pointed out in Simon Peyton Jones's book Implementation of Functional
Programming Languages, section 12.4.3, this preserves laziness best:
the evaluated component value is remembered for the next time the same
component is projected out.

Signed-off-by: Antti-Juhani Kaijanaho <antti-juhani@kaijanaho.fi>
foo
(6 / 0)
  
55gah = lambda f . lambda x . lambda y. (f x, f y)
66xyzzy = lambda x. lambda y. let f = lambda x . x in (f x, f y)
77xyzzy2 = lambda x. lambda y. lambda z. let f = lambda x . z x in (f x, f y)
8
9f = lambda x . x + 1
10pair = (f 2 + 3, f 3)
11fst pair
12snd pair
13pair
hm.y
(6 / 2)
  
10791079 case TE_FST:
10801080 arg = te_app_arg(te);
10811081 if (term_kind(arg) == TE_PAIR) {
1082 replace_term(te, te_pair_fst(arg));
1082 struct term *rt = te_pair_fst(arg);
1083 if (term_reduce_step(rt)) return true;
1084 replace_term(te, rt);
10831085 return true;
10841086 }
10851087 return term_reduce_step(arg);
10861088 case TE_SND:
10871089 arg = te_app_arg(te);
10881090 if (term_kind(arg) == TE_PAIR) {
1089 replace_term(te, te_pair_snd(arg));
1091 struct term *rt = te_pair_snd(arg);
1092 if (term_reduce_step(rt)) return true;
1093 replace_term(te, rt);
10901094 return true;
10911095 }
10921096 return term_reduce_step(arg);