[Haskell-cafe] Re: Some random newbie questions

2005-01-10 Thread John Hughes
I seriously considered switching frlom Hugs to GHC for my introductory 
programming class this year, but in the end stayed with Hugs because of 
a single feature.

I'm teaching beginning programmers, and for them at least, there is an 
overwhelming volume of names to learn -- what's that function? is a 
question they ask themselves often, as is what's that type?. I teach 
them that, whenever they see a name they don't recognise, they can find 
out more about it using the :i command. This is a simple trick to learn, 
that helps them understand points they've missed and catches 
misapprehensions.

My students also see type classes very early. I'll bet yours will too. 
Even if one is very careful to restrict the examples in lectures so as 
to avoid them (which is a bind), as soon as students try out Hugs for 
themselves, they will make mistakes that generate error messages 
referring to type classes. No problem: the question what's that class? 
can ALSO be answered by :i.

Now, at the beginning students have only a very rudimentary 
understanding of classes. A class is a collection of types to them, 
nothing more. In particular, the class definition itself is of little 
use to them, since it often contains a very subtly chosen collection of 
methods (just type :i Show, for example, which students do very early). 
What IS useful, right from the beginning, is the list of instances. What 
are Num types? Oh, integers and reals.  What are Show types? Oh, pretty 
much everything. Particularly when debugging missing instance errors, 
this is just the information you need.

Unfortunately, while Hugs prints the list of instances of a class in 
response to :i, GHCi does not. It only prints the class definition -- 
which, for my students, contains no useful information. For that reason 
alone, I stuck with Hugs last year.

Of course, later in the course there is no problem in introducing GHC as 
well. Students coping well are happy to learn there is a compiler 
available too, while those who are struggling can stay with Hugs 
throughout the course. I demonstrated GHC in order to show them 
wxHaskell (which was very popular with the students), but I didn't 
REQUIRE them to use it.

How about changing the behaviour of :i, Simon, so I can use GHCi 
throughout next year?

John
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Some random newbie questions

2005-01-10 Thread Sebastian Sylvan
On Mon, 10 Jan 2005 10:15:57 +0100, John Hughes [EMAIL PROTECTED] wrote:

 snip
 How about changing the behaviour of :i, Simon, so I can use GHCi
 throughout next year?

Agreed. GHCi also produces what can be perceived as odd output when
typing, for instance, :i +
-- + is a method in class Num
infixl 6 +
(+) :: forall a. (Num a) = a - a - a

What I'm referring to is of course the forall a. which confuses newcomers.

Personally, I'd also like a graphical interface with similar features
as winhugs (mainly the recently opened files list and a graphical
way to alter settings), but maybe that's just me...

/S
-- 
Sebastian Sylvan
+46(0)736-818655
UIN: 44640862
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Some random newbie questions

2005-01-06 Thread karczma
A random newbie called (randomly probably) Benjamin Pierce writes: 

* I wrote a little program for generating Sierpinkski Carpets, and was
  astonished to find that it runs out of heap under Hugs (with standard
  settings -- raising the heap size with -h leads to a happier result).
...
import SOEGraphics 

fillSquare w x y s =
  drawInWindow w ... 

carpet w x y s =
  if s  8 
  then fillSquare w x y s
  else let s' = s `div` 3 
in do carpet w xys'
  carpet w (x+s')   ys'
  carpet w (x+s'*2) ys' 
  carpet w x(y+s')   s'
  carpet w (x+s'*2) (y+s')   s'
  carpet w x(y+s'*2) s'
  carpet w (x+s')   (y+s'*2) s'
  carpet w (x+s'*2) (y+s'*2) s' 

main = 
  runGraphics (
do w - openWindow Carpet (700,700)
   carpet w 50 50 600
   k - getKey w
   closeWindow w
  ) 

  I've clearly got a lot to learn about space usage in Haskell... can
  someone give me a hint about what is the problem here and how it might
  best be corrected?
Interesting (although hardly encouraging...) to see that other
people fell victim of *exactly* the same problem as myself, when
I tried to switch from Scheme to Haskell/Hugs while teaching graphics... 

In any case, Maestro, don't try to put your 'carpet' procedure under
the microscope, since in fact you have been stabbed in the back with an
empoisoned knife. This program, whose complexity can hardly be called
exorbitant also slllosss down, and fails in GC: 

= 

fillSquare w x y s =
drawInWindow w
 (withColor Blue
(polygon [(x,y), (x+s,y), (x+s,y+s), (x,y+s), (x,y)])) 

loopx w x y s =
if xs then return () else do {fillSquare w x y 5; loopx w (x+5) y s} 

blob w x y s =
if ys then return ()
  else do{loopx w x y s; blob w x (y+5) s} 

main = runGraphics (
   do w-openWindow Blob (900,900)
  blob w 50 50 800
  k-getKey w
  closeWindow w
 ) 

===
Greg Buchholz example with generating PS shows that even a non-optimized
program which avoids SOE works... 

It seems that there is something nasty with SOEGraphics, concretely
with window painting procedures (and with other operations iterated,
where the quotes around iteration is a sad irony...). 

It seems that Nothing Is Forgotten, or worse. Well, the following version: 

 

loopx :: Window - Int - Int - Int - IO ()
loopx w x y s =
if xs then return () else (fillSquare w x y 5) `seq` (loopx w (x+5) y s) 

blob :: Window - Int - Int - Int - IO ()
blob w x y s =
if ys then return ()
  else  (loopx w x y s) `seq` (blob w x (y+5) s) 

 

works pretty fast (under Windows 2000). But doesn't paint anything.
Perhaps I should use some deepSeq, or whatever? 

Sorry for not having anything more optimistic to say. In fact, waiting
for better weather I do such exercises using Clean... 

Jerzy Karczmarczuk 

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe