POV-Ray : Newsgroups : povray.off-topic : My first C++ program : Re: A test Server Time
2 Nov 2024 19:16:38 EDT (-0400)
  Re: A test  
From: Orchid XP v8
Date: 20 Sep 2008 17:36:36
Message: <48d56ce4$1@news.povray.org>
Warp wrote:

>>    case compare number target of
> 
>   I think this line illustrates well what I wrote earlier. Just a list
> of whitespace-sepaated words. No delimiters, no hints about what might be
> a reserved keyword, what might be a variable, what might be a function.

Fair point.

The following are reserved keywords in Haskell:

   module, where, import, qualified, hiding, as, case, of, let, in, 
data, type, newtype, class, instance, deriving, do

I'm pretty sure that's the complete list. I count 17 reserved words. (A 
quick Google search indicates that C++ has roughly 90 of 'em.) If you 
see any of these words, it's a keyword.

(It's actually kinda irritating that "in" and "as" are keywords; these 
would make convinient variable names from time to time, e.g., handles 
named "in" and "out". But, alas, no...)

>   I'm no at all sure how that should be parsed. Could it, perhaps, be
> something like:
> 
>     case(compare(number, target)) of
> 
>   What would be wrong with a syntax like that?

You can write

   case (compare number target) of

if you prefer. This is completely valid syntax.

Now, if it was pretty-printed like THIS:

   http://hpaste.org/10565

you wouldn't be as confused. (?) If you have some kind of text editor 
with syntax-hilighting, this isn't an issue. (I don't know anything 
about Emacs, but I imagine it can't be hard to program it so that just 
the 17 words above print in a different colour...)

As for why functions aren't called like foo(x, y, z) like in C... that's 
due to function currying. In Haskell, you say "foo x y z" because then 
you can write "foo x y" to mean a function that just accepts "z". (Or 
just "foo x" for one that accepts "y" and "z", or "foo" for the function 
itself, or whatever.)

Note that you *can* write foo (x, y, z) in Haskell, because "(x, y, z)" 
is what Haskell calls a "tuple". This has a different type though. (It's 
like the difference between calling a C++ function with an array verses 
a vector. Same concept, different implementation - and type.) This is a 
so-called "uncurried function", and they aren't used much.

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.