On Mon, Sep 8, 2014 at 9:51 PM, Matthias Felleisen <matth...@ccs.neu.edu> wrote:
On Sep 4, 2014, at 12:54 PM, Daniel Bastos wrote: > > > A candidate for a solution. (I'm not sure I'm correct regarding the > > function project. The description says "a lists of lists" (which I > > translate to (listof ITEM)) and "a function from lists to Xs", so I > > wonder if the domain of this function-argument must be (listof ITEM) > > or it could be more general such as (listof Y). I decided to imagine > > that the domain of the function-argument would be items of the "list > > of lists" and so I made it into (listof ITEM). > > > In this context ITEM and X and Y are variables (placeholders) that stand > for sets (classes) of data. > > In the following I have translated the purpose statements for these > functions into prototype calls: > > > sort: (listof ITEM) (ITEM ITEM -> boolean) -> (listof ITEM) > > > (sort a-list-of-Xs compare-Xs) : a-list-of-Xs > (same Xs indeed, but rearranged) > > > map: ((listof ITEM) -> X) (listof ITEM) -> (listof X) > > (map a-function-from-item-on-list-to-X a-list-of-ITEMs) : a-list-of-Xs > > > > > project: (listof (listof ITEM)) ((listof ITEM) -> (listof X)) -> (listof > X) > > (project a-list-of-list-of-ITEMs a-function-from-list-of-ITEMs-to-X) : > a-list-of-Xs > > > (*) Comparison with exercise 20.2.2 > > Abstraction works by taking two concrete examples and replacing matching > concrete things with variables. > > 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. Indeed. (That was map.) Thank you. (*) Candidate for solution for exercise 20.2.4 Our approach will be to take two concrete examples and replace matching concrete things with variables. (-) Sort sort1: (listof number) (number number -> boolean) -> (listof number) sort2: (listof name) (name name -> boolean) -> (listof name) sort: (listof ITEM) (ITEM ITEM -> boolean) -> (listof ITEM) Type variable: ITEM. (-) Map map1: (number -> number) (listof number) -> (listof number) map2: (name -> name) (listof name) -> (listof name) map: (x -> x) (listof x) -> (listof x) Type variable: x. (-) Project project1: (listof (listof symbol)) ((listof symbol) -> symbol) -> (listof symbol) project2: (listof (listof name)) ((listof name) -> name) -> (listof name) project: (listof (listof x)) ((listof x) -> x) -> (listof x) Type variable: x.
____________________ Racket Users list: http://lists.racket-lang.org/users