[plt-scheme] HTDP 21.1.2

From: Richard Cobbe (cobbe at ccs.neu.edu)
Date: Thu Jul 13 07:07:16 EDT 2006

On Thu, Jul 13, 2006 at 10:38:29AM +0100, wooks . wrote:

> >From: Richard Cobbe <cobbe at ccs.neu.edu>

> >On Tue, Jul 11, 2006 at 01:58:09PM +0100, wooks . wrote:
> >
> >> fold is a reducing function - produces a consolidated value from
> >> multiple inputs (eg list).
> >>
> >> map is a one to one function.
> >>
> >> So there is a mismatch at contract level  (hence why methinksh trick
> >> question) .

Ok, it seems I was a little oblique -- sorry about that.

Since you mentioned contracts, the problem I thought you were having was
one I've seen a lot in students.  They look at the contracts for map and
    map :: (X -> Y) (Listof X) -> (Listof Y)
    fold :: Y (X Y -> Y) (Listof X) -> Y

and say, "OK, map returns a list, but since fold's contract just ends in
Y, there's no way it can be a list," temporarily forgetting that Y can
be any type at all, even a list.

Sounds like that's not the major stumbling block, though.

How about this: map also produces a consolidated value from a list -- it
just happens that the consolidated value is always a list.

(It's possible that Felix's posts have addressed this -- due to a paper
deadline, I haven't read them yet.)


Posted on the users mailing list.