<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Sep 8, 2014 at 9:51 PM, </div><div class="gmail_quote">Matthias Felleisen <span dir="ltr"><<a href="mailto:matthias@ccs.neu.edu" target="_blank">matthias@ccs.neu.edu</a>></span> wrote:</div><div class="gmail_quote"><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span>On Sep 4, 2014, at 12:54 PM, Daniel Bastos wrote:<br>
<br>
> A candidate for a solution. (I'm not sure I'm correct regarding the<br>
> function project. The description says "a lists of lists" (which I<br>
> translate to (listof ITEM)) and "a function from lists to Xs", so I<br>
> wonder if the domain of this function-argument must be (listof ITEM)<br>
> or it could be more general such as (listof Y). I decided to imagine<br>
> that the domain of the function-argument would be items of the "list<br>
> of lists" and so I made it into (listof ITEM).<br>
<br>
<br>
</span>In this context ITEM and X and Y are variables (placeholders) that stand for sets (classes) of data.<br>
<br>
In the following I have translated the purpose statements for these functions into prototype calls:<br>
<span><br>
> sort: (listof ITEM) (ITEM ITEM -> boolean) -> (listof ITEM)<br>
<br>
<br>
</span>(sort a-list-of-Xs compare-Xs) : a-list-of-Xs<br>
  (same Xs indeed, but rearranged)<br>
<span><br>
> map: ((listof ITEM) -> X) (listof ITEM) -> (listof X)<br>
<br>
</span>(map a-function-from-item-on-list-to-X a-list-of-ITEMs) : a-list-of-Xs<br>
<span><br>
<br>
<br>
> project: (listof (listof ITEM)) ((listof ITEM) -> (listof X)) -> (listof X)<br>
<br>
</span>(project a-list-of-list-of-ITEMs a-function-from-list-of-ITEMs-to-X) : a-list-of-Xs<br><span><br>
> (*) Comparison with exercise 20.2.2<br><br>
</span>Abstraction works by taking two concrete examples and replacing matching concrete things with variables.<br>
<br>
20.2.2 asks you to come up with contracts for functions that work on one basic kind of data. Use a distinct kind and then apply the abstraction design recipe. You will find that at least one of the above is wrong.</blockquote><div><br></div><div>Indeed. (That was map.) Thank you.</div><div><br></div><div>(*) Candidate for solution for exercise 20.2.4<br></div><br>Our approach will be to take two concrete examples and replace matching concrete things with variables.</div><div class="gmail_quote"><br></div><div class="gmail_quote"><div>(-) Sort </div><div><br></div><div>sort1: (listof number) (number number -> boolean) -> (listof number)<br></div><div>sort2: (listof name) (name name -> boolean) -> (listof name)</div><div>sort: (listof ITEM) (ITEM ITEM -> boolean) -> (listof ITEM)</div><div><br></div><div>Type variable: ITEM.</div><div><br></div><div>(-) Map</div><div><br></div><div>map1: (number -> number) (listof number) -> (listof number)<br></div><div>map2: (name -> name) (listof name) -> (listof name)</div><div>map: (x -> x) (listof x) -> (listof x)</div><div><br></div><div>Type variable: x.</div><div><br></div><div>(-) Project</div><div><br></div><div>project1: (listof (listof symbol)) ((listof symbol) -> symbol) -> (listof symbol)<br></div><div>project2: (listof (listof name)) ((listof name) -> name) -> (listof name)</div><div>project: (listof (listof x)) ((listof x) -> x) -> (listof x)</div><div><br></div><div>Type variable: x.</div><div><br></div></div></div></div>