|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Darren New <dne### [at] sanrrcom> wrote:
> I think c ! 2 is the third element of c, not unlike c[2].
[] is used almost universally for indexing in most languages (not only
for random access of arrays, but also eg. accessing relational sets (where
the thing inside the square brackets is the key and the return value is the
data)). Is there a logical reason why Haskell chooses an odd syntax of
"x ! y" for the same thing than most other languages express as "x[y]"?
Using ! for the nth element is not very expressive. In mathematics ! is
usually used for factorials, in many programming languages it's used to
express logical negation (granted, not a very logical choice per se, but
quite established), and in natural languages it's used to express shouting
or to emphasize the importance of something (like "WARNING!").
So why choose ! as "the nth element"? Did they run out of obfuscated
one-character operators and it was the only one left? Or is there a logical
reason to choose that symbol out of all possible that I'm not aware of?
(Well, I wouldn't actually be surprised if that symbol had been used for
that purpose in some weird mathematical notations eg. in some lambda
calculus or the like since the 1930's or such.)
I know Haskells undying love for obfuscating brevity, but would it have
hurt to actually use a descriptive *name* for that function? I don't know,
like "c element_at 2" (or even "c at 2") or whatever.
Btw, what is logical not in Haskell?
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Orchid XP v8 wrote:
> just mildly curious to know whether you can implement your own
> tokenising rules or not.
You're actually reading the input from the file. How could you *not*
implement your own tokenizing rules?
--
Darren New, San Diego CA, USA (PST)
The question in today's corporate environment is not
so much "what color is your parachute?" as it is
"what color is your nose?"
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Warp wrote:
> [] is used almost universally for indexing in most languages
Well, most based on C syntax. The rest (Pascal, Fortran, Ada, etc) use ().
> data)). Is there a logical reason why Haskell chooses an odd syntax of
> "x ! y" for the same thing than most other languages express as "x[y]"?
I would guess it makes the thing into an infix operator, while x[y] is
neither prefix, postfix, infix, or ... whatever.
Plus, list literals are [ ... ], so I'm guessing that x [ y ] is ambiguous
as to whether you're calling function x with an argument htat's a
one-element list containing y.
Now, why they picked ! instead of (say) @ is beyond me. "@" is what I've
seen used in all the languages that make this strictly an infix operator.
--
Darren New, San Diego CA, USA (PST)
The question in today's corporate environment is not
so much "what color is your parachute?" as it is
"what color is your nose?"
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Warp wrote:
> [] is used almost universally for indexing in most languages.
Granted.
> Is there a logical reason why Haskell chooses an odd syntax of
> "x ! y" for the same thing than most other languages express as "x[y]"?
Yeah. "x[y]" would mean a function call, where "x" is the function name,
and the function's argument is a 1-element list containing "y".
To put it another way, Haskell uses square brackets for lists. So you
can't use it for indexing as well.
(Well, OK, if you changed the parsing rules of the language, you could.
You could make it so that if you want "x[y]" to be a function call, you
*must* put a space in there, otherwise it's an index. They already do
this with dots; "x . y" is function composition, but "x.y" is a
qualified name.)
> Using ! for the nth element is not very expressive. In mathematics ! is
> usually used for factorials, in many programming languages it's used to
> express logical negation (granted, not a very logical choice per se, but
> quite established), and in natural languages it's used to express shouting
> or to emphasize the importance of something (like "WARNING!").
For what it's worth, "!" is used for arrays and dictionaries. For lists
you use "!!". This is because indexing a list is obviously an O(n)
operation, which is bad. So if you find yourself writing "!!", you
should probably go check that there isn't some more performant way to do
what you're trying to do. (Like use an array or something.)
Thus, using "!!" for a list sort-of makes sense. But for an array, "!"
is O(1), so... um...
(Small footnote: You can't have unary operators, so there's no chance of
using "!" for factorial. Unfortunately.)
> So why choose ! as "the nth element"? Did they run out of obfuscated
> one-character operators and it was the only one left?
...pretty much, yes.
Arguably "@" would be more logical - but that's a resurved symbol. I
suppose you could use "@@", but that's not terribly elegant.
I suspect what _really_ happened here is that when Haskell was first
designed, it didn't *have* indexing at all. And then later, when Haskell
became real-world enough to need it, they wrote it as a library, and
didn't want to change the whole syntax of the language just to support
arrays, so they just picked an available symbol name.
> I know Haskells undying love for obfuscating brevity, but would it have
> hurt to actually use a descriptive *name* for that function? I don't know,
> like "c element_at 2" (or even "c at 2") or whatever.
You can't do "c at 2", but there's no reason you couldn't do "c `at` 2".
(Hell, if you utter the simple incantation "at = (!)" then the above
will suddenly work. But that's obviously not the same thing has having
the standard libraries implement it that way...)
> Btw, what is logical not in Haskell?
You're going to love this...
It's "not". As in "not (x == y)".
(Of course, any sane person would write "x /= y" instead. Since most
binary comparison operations have negated versions, you don't often need
the not operator itself.)
For completeness, AND is "&&" and OR is "||". (Since "|" is already used
for pattern guards.) Not too unusual.
Oh, and bitwise operations [which aren't available until you import the
necessarily library] are ".&." and ".|.". No specific reason. Bitwise
not is "complement".
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Darren New wrote:
> I would guess it makes the thing into an infix operator, while x[y] is
> neither prefix, postfix, infix, or ... whatever.
The word you're looking for is apparently "mixfix".
> Plus, list literals are [ ... ], so I'm guessing that x [ y ] is
> ambiguous as to whether you're calling function x with an argument
> htat's a one-element list containing y.
Yeah. Although like I said in my other reply, they already made
whitespace significant in the case of the "." character. I'm guessing
this one's a historical accident.
> Now, why they picked ! instead of (say) @ is beyond me.
That would have been a better choice, but it's already taken. (And not
even by another library function - it's actually *reserved* in the
syntax rules.)
You could have had "@@", but they chose "!" for whatever reason...
Then again, this is the same language that gives you "^" and "**". Wanna
take a guess what the difference is?
Haskell is a brilliant language, but I never said it was perfect. ;-)
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Orchid XP v8 <voi### [at] devnull> wrote:
> You can't do "c at 2", but there's no reason you couldn't do "c `at` 2".
If this were C++, it would actually be "c.at(2)" (in fact, with indexable
STL containers it not only *would* be, but actually *is* like that; well, at
least if you want boundary checks that is.)
But I suppose that since Haskell is not an OO language and its dot operator
probably means something else altogether, making it like that would probably
be difficult (and would probably require a complete syntax redesign).
> > Btw, what is logical not in Haskell?
> You're going to love this...
> It's "not". As in "not (x == y)".
Why suddenly have one operator be a comprehensible word? Were they
uninspired when they thought up that one? :P
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
On 02/27/10 14:39, Warp wrote:
> Darren New <dne### [at] sanrrcom> wrote:
>> I think c ! 2 is the third element of c, not unlike c[2].
>
> [] is used almost universally for indexing in most languages (not only
> for random access of arrays, but also eg. accessing relational sets (where
> the thing inside the square brackets is the key and the return value is the
> data)). Is there a logical reason why Haskell chooses an odd syntax of
> "x ! y" for the same thing than most other languages express as "x[y]"?
>
> Using ! for the nth element is not very expressive. In mathematics ! is
> usually used for factorials, in many programming languages it's used to
> express logical negation (granted, not a very logical choice per se, but
> quite established), and in natural languages it's used to express shouting
> or to emphasize the importance of something (like "WARNING!").
>
> So why choose ! as "the nth element"? Did they run out of obfuscated
> one-character operators and it was the only one left? Or is there a logical
> reason to choose that symbol out of all possible that I'm not aware of?
> (Well, I wouldn't actually be surprised if that symbol had been used for
> that purpose in some weird mathematical notations eg. in some lambda
> calculus or the like since the 1930's or such.)
>
> I know Haskells undying love for obfuscating brevity, but would it have
> hurt to actually use a descriptive *name* for that function? I don't know,
> like "c element_at 2" (or even "c at 2") or whatever.
Now you know how lots of people feel when they have to learn UNIX
(command line). At some point, you just tell them, "Hey, that's the way
it is. Weird, obscure, but works, and doesn't really get in your way
once you know it".
--
Depend on the rabbit's foot if you will, but remember, it didn't help
the rabbit.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Warp <war### [at] tagpovrayorg> wrote:
> Darren New <dne### [at] sanrrcom> wrote:
> > I think c ! 2 is the third element of c, not unlike c[2].
>
> [] is used almost universally for indexing in most languages (not only
> for random access of arrays, but also eg. accessing relational sets (where
> the thing inside the square brackets is the key and the return value is the
> data)). Is there a logical reason why Haskell chooses an odd syntax of
> "x ! y" for the same thing than most other languages express as "x[y]"?
>
> Using ! for the nth element is not very expressive. In mathematics ! is
> usually used for factorials, in many programming languages it's used to
> express logical negation (granted, not a very logical choice per se, but
> quite established), and in natural languages it's used to express shouting
> or to emphasize the importance of something (like "WARNING!").
Like Scheme using it to warn about bad imperative constructs, like (set! v 1) :)
> So why choose ! as "the nth element"?
v!1 is briefer than v[1] :)
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
>> You can't do "c at 2", but there's no reason you couldn't do "c `at` 2".
>
> If this were C++, it would actually be "c.at(2)".
OK.
> But I suppose that since Haskell is not an OO language and its dot operator
> probably means something else altogether, making it like that would probably
> be difficult (and would probably require a complete syntax redesign).
The dot can mean two different things. "x . y" means function
composition. "x.y" is a qualified name. (It means the variables "y" from
module "x".)
>> You're going to love this...
>
>> It's "not". As in "not (x == y)".
>
> Why suddenly have one operator be a comprehensible word? Were they
> uninspired when they thought up that one? :P
Heh. If you mean "why isn't it some random symbol?" then the answer is
"you can only use symbols for *binary* functions, not *unary* functions
such as NOT".
Oh, you're going to love this... The logical AND and OR functions are
"&&" and "||" respectively, but Haskell *also* has functions named "and"
and "or". They take the logical AND or OR of a list of booleans.
Hey, I said Haskell was a great language. I never said the standard
libraries were perfect. ;-) I'm sure you can probably name a few
unfortunately design choices of the C++ libraries too...
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Neeum Zawan wrote:
> Now you know how lots of people feel when they have to learn UNIX
ls, cp, mv, rn and friends. Becuase, let's face it, adding two octets to
cp to make copy would be a crime...
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
|
|