| 
  | 
> The hard thing about writing a tutorial is that by the time you're 
> experienced enough to be an authority on the language, half the stuff that 
> trips newbies up is so utterly "obvious" to you that you forget to even 
> mention it.
Exactly.
> In truth, if you're using tuples bigger than about three or four elements, 
> you really ought to define a custom type for this stuff instead of relying 
> on tuples.
OK.  I take it a custom type is a bit like a struct in C-type languages, in 
that it can hold any number of different types?
> I can talk some more if you want?
Once you know a few basic things I think it's best to move on to simple 
examples (small multi-line samples, not those artificial ones needed for the 
web).
> > let factorial n = product [1..n]
> > let choose n k = (factorial n) / (factorial k * factorial (n - k))
> > choose 3 5
Exactly.  Even I can work out from that one how functions are defined now 
:-)
BTW what would happen if I typed "choose 3 (-5)" instead?
I'm just trying to think of a subject for a good example ... how about a 
card game?  Firstly how would you represent the cards (tuple or custom type 
for the suit/value?).  Then I assume you would just create a list of "Cards" 
to represent a group of cards that someone was holding (say 5 cards).  How 
would you then check to see if any two cards in that list were the same 
value, or all the same suit, etc?
> Are you actually interested enough to want to play with it more?
I was interested enough in J to learn how to use it to write a mandelbrot in 
1-line :-)  Haskell should be a doddle - at least you stand to pick up bits 
and pieces based on English, rather than just almost random single 
characters for everything!
 
 Post a reply to this message 
 | 
  |