From leavens@cs.iastate.edu Mon Dec 2 07:32:18 2002 Date: Mon, 2 Dec 2002 07:31:53 -0600 (CST) From: Gary T. Leavens To: Becca Wemhoff Cc: cs541s@cs.iastate.edu Subject: Re: what constitutes "just by using functions in the Prelude"? Hi Becca, On Mon, 2 Dec 2002, Becca Wemhoff wrote: > For 2b (write just by using function in the Haskell Prelude), > can we use helper functions? > Or do you want some clever choice of the functions from the > Prelude so that it's all in one expression? I think it's okay to use helper functions and other stuff as long as you use something from the prelude. All in one expression would be better, but I'm not sure how to do that myself. > Also, may we use list comprehensions (that use zip, e.g.) when > you're only looking for Prelude functions? Yes. -- 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@larch.cs.iastate.edu Mon Dec 2 09:48:55 2002 Date: Mon, 2 Dec 2002 09:45:00 -0600 (CST) From: Gary T. Leavens To: yaping@iastate.edu Subject: Re: 541 - hw5 - problem 17 Hi Yaping, On Mon, 2 Dec 2002 yaping@iastate.edu wrote: > I don't have any clue why I can't hide map function from Prelude while other > operator (such as ++, - .. ) functions can be hided successfully. Here are the > statements I typed: > > module MyMap where > import Prelude hiding ((map)) > .. Don't put an extra pair of parentheses around "map", use: import Prelude hiding (map) See the grammar for Haskell in the Report http://haskell.org/onlinereport/modules.html > Also, on popeye at Prelude prompt, the statement like (13 'div' 5) doesn't > work, but (div 13 5) works, so why such difference? You need to use backquotes ` not normal quotes ' for this. On my keyboard the backquote is on the far left at the top. -- 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 Tue Dec 3 10:06:24 2002 Date: Tue, 3 Dec 2002 10:05:57 -0600 (CST) From: Gary T. Leavens To: Becca Wemhoff Cc: Georgiy Ushakov , Gary Leavens Subject: Re: syntactic sugar in Haskell? Becca, On Tue, 3 Dec 2002, Becca Wemhoff wrote: > Do we need to worry about the syntactic sugar our hugs may or may > not do? > > In particular, > my answer to last example in (10) is [3, 4] versus 3 : (4 : []) > > my answer to first example in (12) is []::String versus "" > > Same answers -- my equality comparison returns True. Yes, that's fine. These are equivalent, and you don't have to worry about the differences. > Is there a way to specify how you want the output to look? Yes, you can use the "show" function to display the results. My shortcut uses the -u option that suppresses this, but if you use that, then you get to write the instance of Show that displays results. -- 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@larch.cs.iastate.edu Wed Dec 11 23:26:32 2002 Date: Wed, 11 Dec 2002 19:41:16 -0600 (CST) From: Gary T. Leavens To: Computer Science 541 , George Ushakov , Satish Kumar Vemula , Tongjie Chen Subject: Closures in C (and Haskell) Hi all, I received the following mail from a D. Ritchie :-): > Subject: Can't I make closures in C? > > I've been hearing some fuss about "lambda" (\ in Haskell) and I just don't > get it. What's the big deal? I can do all this in my favorite > langauge: C. For example, consider everybody's favorite > example of a curried function in Haskell, which is the following > curried version of +. > > -- curried addition in Haskell > cadd = (\ x -> (\ y -> x + y)) > > For example, ((cadd 2) 3) returns 5. > > But in C, functions are objects too, and I can pass around function > pointers. So consider the following program to do curried addition. > > /* curried addition program in ANSI C */ > #include > > typedef int (*func)(int); /* functions that take and return ints */ > > int takes_y(int y) { return(x + y); } > > func cadd(int x) { return(&takes_y); } > > int main() { printf("%i\n", (cadd(2))(3)); } > > I just about have this working, and it seems like it does the > same thing as the SML code. (Only problem is that the variable > "x" used in "takes_y" is undefined, but I'll fix that soon.) > Doesn't this prove that Haskell, and "\" are no big deal? Can you see any flaw in D. Ritchie's argument? -- 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@larch.cs.iastate.edu Thu Dec 12 15:04:34 2002 Date: Thu, 12 Dec 2002 15:03:34 -0600 (CST) From: Gary T. Leavens To: Computer Science 541 , George Ushakov , Satish Kumar Vemula , Tongjie Chen Subject: Class room for review session for 541 Hi, We have 214 Atanasoff Hall for our review session on Thursday at 1:10pm to 2pm. At that time we'll review for the 541 test. Please come prepared with any questions; I'll also try to make some up, and you can look at the study guide I'll make available shortly... -- 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