From leavens@larch.cs.iastate.edu Wed Jan 26 10:22:38 2005 Date: Wed, 26 Jan 2005 10:22:38 -0600 (CST) From: Gary T. Leavens To: Michael McCown Cc: Com S 342 Staff , Daniel Patanroi Subject: Re: COMS 342: Exercise 2 and homework 2 in Com S 342 Hi Michael, On Wed, 26 Jan 2005, Michael McCown wrote: > Section 2 meets today also, do we get to turn in with out penalty? Since there are 6 hours before it meets, I was hoping students in section 2 could just do it. But if this is a hardship for you, I'm willing to accept it without penalty tomorrow. But you should still come to the discussion section, even if you don't have time to do the exercise today. Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ------------------------------------------------------- From leavens@cs.iastate.edu Wed Jan 26 20:37:35 2005 Date: Wed, 26 Jan 2005 20:37:35 -0600 (CST) From: Gary T. Leavens To: Matthew J. Ring Cc: cs342s@cs.iastate.edu Subject: Re: deftype for curried functions Hi Matt, On Wed, 26 Jan 2005, Matthew J. Ring wrote: > I'm trying to write the deftype for question 1, but I can't find any > examples that relate to the multiple lambda's in the lecture notes or on the > web site. > > I know that one of them is as follows: > > (deftype average3-c (-> (number) number)) > > But I don't know what to do with the other two params that are in separate > lambda's. Are there any notes on the web that I didn't see that would give > examples of this? In the lecture notes I have: procedure: (lambda (ls1 ls2 ls3) (append ls1 (append ls2 ls3))) ;; TYPE: (forall (T) ;; (-> ((list-of T) (list-of T) ;; (list-of T)) ;; (list-of T))) curried form: (lambda (ls1) (lambda (ls2) (lambda (ls3) (append ls1 (append ls2 ls3))))) ;; TYPE: (forall (T) ;; (-> ((list-of T)) ;; (-> ((list-of T)) ;; (-> ((list-of T)) ;; (list-of T))))) procedure: (lambda (x y) (+ x y)) ;; TYPE: (-> (number number) ;; number) curried form: (lambda (x) (lambda (y) (+ x y))) ;; TYPE: (-> (number) ;; (-> (number) ;; number)) These don't use deftypes, since we aren't using define. To do that we could write, for example: (deftype append3-c (forall (T) (-> ((list-of T)) (-> ((list-of T)) (-> ((list-of T)) (list-of T)))))) (define append3-c (lambda (ls1) (lambda (ls2) (lambda (ls3) (append ls1 (append ls2 ls3)))))) ;; and (deftype cadd (-> (number) (-> (number) number))) (define cadd (lambda (x) (lambda (y) (+ x y)))) There are some more examples in the code examples page under "Procedures": http://www.cs.iastate.edu/~leavens/ComS342/code-examples.shtml#Procedures but not all of these have types. (These are also in the course library, but the web page above tells you where to look.) The grav-force example doesn't have deftypes, but uses the same notation for units. The type-check-unify's example has a doosey of a type: (deftype tc:list-unify-maker (forall (T) (-> ((-> (T T (tc:env-of uniq-sym tc:type-expr) (list-of tc:variable)) (maybe-of (tc:env-of uniq-sym tc:type-expr)))) (-> ((list-of T) (list-of T) (tc:env-of uniq-sym tc:type-expr) (list-of tc:variable)) (maybe-of (tc:env-of uniq-sym tc:type-expr)))))) The best example is probably the one in $PUB/lib/vector-generator.scm: (deftype vector-generator (forall (T) (-> ((-> (number) T)) (-> (number) (vector-of T))))) The type notation itself is defined in http://www.cs.iastate.edu/~cs342/docs/typedscm_toc.html But could use more examples... Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 --------------------------------------- From leavens@cs.iastate.edu Sat Jan 29 20:52:20 2005 Date: Sat, 29 Jan 2005 20:52:20 -0600 (CST) From: Gary T. Leavens To: Sayan Ranu Cc: cs342s@cs.iastate.edu Subject: Re: hw q 5 and 6 Hi Sayan, On Sat, 29 Jan 2005, Sayan Ranu wrote: > This might be a stupid question, but I could not understand what get-name > does in question 5 and 6? I didn't tell you what get-name does. You can imagine it returns the "name" from a list (by position, say). > Also are we supposed to list the procedures which are > syntactically correct for recursion, or something else ? Thanks You're supposed to list the ones that follow the grammar correctly. Part of that is correct syntax, but I think all parts are correct in terms of syntax. Some are not type correct, and some don't follow the normal recursion pattern. See $PUB/docs/follow-grammar-flat.txt for a definition of what it means to "follow the grammar" for flat lists. Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580