|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
scott wrote:
> I've definitely got annoyed by some sites where you hit the back button
> and it takes you to a site you were looking at 10 minutes ago, because
> all the things you've been doing on this site haven't actually loaded a
> new page...
Yeah, this is a lot of fun.
The other one is "JavaScript links". You know, where the "link" isn't
actually a hyperlink, it executes some JavaScript, which then tells the
browser to change URL. And because it's scripted, you can't Ctrl+click
to open the URL in a new window. (Or if you do, the existing window
changes URL anyway, so you *still* don't have the original page. At
least you can usually use the browser history to go back a page though.)
And then there's the links which pop up a "window" over the current
page. You know the kind - the whole page goes grey and a funky little
box appears over the top of it, and you can't do anything with the rest
of the page until you dismiss the box. (Modal dialogs suck for a reason!)
Lots of shopping sites like to take you to a completely different page
as soon as you've bought something, which also tends to thwart any
attempt to used tabbed browsing to nagivate around. You've got a page of
items, but as soon as you buy one, the page goes away. Great. Now I have
to somehow navigate back to where I just was...
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Invisible wrote:
> Seems reasonably clear...
Hmm, I wonder if I could use this to implement distributed MVC, like in
my Final Year Project, but without requiring a custom client.
Of course, as far as I can tell, I need a real web server to even
experiment with this stuff, so...
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
scott wrote:
> The tutorial was good up until step 7.
Hmm, maybe I should write my own?
> 2 + 2
That was easy, eh?
> 2 + 3 * 4
The usual operator precedence rules apply.
> (2 + 3) * 4
You can override operator precedence manually in the usual way.
> sqrt 144
This is a function call. (Notice the lack of brackets!)
> div 10 3
This is a 2-argument function. (Again, notice the lack of any brackets.)
It performs integer division (i.e., division to the nearest whole number.)
> 10 / 3
Does the same calculation, but with floating-point arithmetic.
> 10 `div` 3
This does the same thing as the first one, but it looks more natural.
The backticks work for any 2-argument function.
> sin 1 + cos 1
This is sin(1) + cos(2).
> sin (1 + cos 1)
This does a different calculation.
> sin -1
This gives an error, because it thinks you mean "sin - 1", which is
invalid. (Yes, we all think it's very annoying.)
> sin (-1)
This works properly.
> "This is a string."
> 'X'
This is a single character.
> "X"
This is a string that only contains 1 character.
> ""
This is an empty string.
> [8, 3, 11, 2]
This is a list of numbers.
> ['X', 'Y', 'Z']
This is a list of characters. Note that a string *is* a list of characters!
> ['X', 3]
A list can contain elements of any type, but all elements must be of
*the same* type. This example is therefore invalid. (Nice clear error
message, eh?)
> sort [8, 3, 11, 2]
> reverse [8, 3, 11, 2]
> sum [8, 3, 11, 2]
> 3 `elem` [8, 3, 11, 2]
> 4 `elem` [8, 3, 11, 2]
Haskell has many, many list functions.
> [1, 2, 3] ++ [4, 5, 6]
This joins two lists together.
> [1..10]
This is a shorthand for writing lists.
> sum [1..100]
Add up these numbers.
> product [1..100]
Multiply these numbers. (Notice that even though the answer is huge,
Haskell computes it exactly.)
> take 3 [5,4,6,3,7,2,8,1,9]
Get the first 3 elements.
> drop 3 [5,4,6,3,7,2,8,1,9]
Remove the first 3 elements.
> [5,4,6,3,7,2,8,1,9] !! 5
Get the 6th element. (The first element is index zero, not index one!)
> filter odd [5,4,6,3,7,2,8,1,9]
Filter a list according to a condition.
> filter (> 5) [5,4,6,3,7,2,8,1,9]
Filter with a different condition.
> map (*2) [5,4,6,3,7,2,8,1,9]
Double all the numbers in the list.
> map toUpper "This is a string."
Since strings are just lists that contain characters, all list functions
work on strings.
> sin
You can't print this out, so you get an error.
> :t sin
This tells the interpretter to only print the type signature, not
*execute* the code. (This is an interpretter command, not a Haskell
command.)
> (5, 'x')
This is a "tuple". Tuples can contain any number of elements, and they
can be of different types. Their main use is in returning several
results from a single function call.
> partition odd [5,4,6,3,7,2,8,1,9]
This splits the list into two lists, containing odd and not-odd numbers.
The lists are returned as a size-2 tuple.
> :t fst
Take a look at this type signature. Can you figure out what it means?
> fst (5, 'x')
Did that do what you expected?
> let x = 5 in x + 1
This is how you define local variables. (The interpretter unfortunately
doesn't let you define things and then use them later. Everything has to
go into a single giant let-expression.)
> let x = 5; y = 8 in x + y
This is how you define multiple variables.
> iterate (*2) 1
This starts with 1, and applies the "times two" function to it over and
over again, creating an infinite list of results. (Again, the
interpretter doesn't display the whole thing.)
> let factorial n = product [1..n] in factorial 6
This is how you define a new function. (Normally it wouldn't be a local
variable, but the interpretter unfortunately doesn't allow top-level
definitions.)
> :t (+1)
This is a function that adds one to a number.
> :t (*2)
This is a function that multiplies a number by two.
> :t (+1) . (*2)
The "." operator takes two functions and combines them together. Here
we've made a function that takes a number, multiplies it by two and then
adds one. (Note carefully the order - RIGHT TO LEFT!)
> map ((+1) . (*2)) [1..10]
Apply this function to a list of numbers.
> :t div
This is a 2-argument function that does integer division.
> :t div 10
This is not a syntax error. It's a 1-argument function. WTF?
> :t div 10 5
This is a calculation that produces a number.
> div 10 5
This divides 10 by 5.
> map (div 10) [1..10]
See if you can work out what's going on.
OK, I'm going to stop now...
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Invisible wrote:
> Of course, as far as I can tell, I need a real web server to even
> experiment with this stuff, so...
You have a real web server.
--
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
scott wrote:
> Can the script intercept this and provide its own "back" functionality?
GIYFT!
--
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
>> Of course, as far as I can tell, I need a real web server to even
>> experiment with this stuff, so...
>
> You have a real web server.
I do, but it can only serve static HTML. (Plus it's quite a lot of work
continually logging into the web interface to re-upload your files every
time you edit 1 line of code.)
I think to try this out properly I'd have to set up a local Apache VM or
something. (This requires me figuring out how the hell to set up
Apache.) Alternatively, I could just write a trivial Haskell webserver
that will log what requests the browser is sending in response to by code...
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
> Hmm, maybe I should write my own?
It's very useful for an absolute beginner, these are the things you need to
know that a lot of tutorials assume you somehow magically know already.
> > :t fst
> Take a look at this type signature. Can you figure out what it means?
>
> > fst (5, 'x')
> Did that do what you expected?
Well it seems to return the first item from a tuple.
Is it just a shorthand for "take 1"?
Ah no, it seems those list operators don't work with tuples :-(
> > let x = 5 in x + 1
> This is how you define local variables. (The interpretter unfortunately
> doesn't let you define things and then use them later. Everything has to
> go into a single giant let-expression.)
So this means "let x = 5 in (the following expression)..."
Now Step 7 in the original tutorial makes sense :-)
> OK, I'm going to stop now...
OK I need to download the compiler if I am to actually learn any of this...
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Invisible wrote:
> I do, but it can only serve static HTML.
Uh, no. Every major OS comes with a real web server.
Now, if what you mean is "I don't have my own computer", then that's a
different question.
> (Plus it's quite a lot of work
> continually logging into the web interface to re-upload your files every
> time you edit 1 line of code.)
Unless you're using an IDE, yes. ;-)
> I think to try this out properly I'd have to set up a local Apache VM or
> something. (This requires me figuring out how the hell to set up
> Apache.)
Depoending on your OS and distribution, this can be pretty trivial.
But if you're actually going to get into AJAX programming, you're going to
have to learn more than you can by asking people here to explain it to you. ;-)
--
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
scott wrote:
>> Hmm, maybe I should write my own?
>
> It's very useful for an absolute beginner, these are the things you need
> to know that a lot of tutorials assume you somehow magically know already.
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. (Plus you're all excited and you want to jabber
incoherently about the cool stuff, not the dry old "this is how you
escape a newline character".)
>> > :t fst
>> Take a look at this type signature. Can you figure out what it means?
>>
>> > fst (5, 'x')
>> Did that do what you expected?
>
> Well it seems to return the first item from a tuple.
>
> Is it just a shorthand for "take 1"?
>
> Ah no, it seems those list operators don't work with tuples :-(
It's all in the type signature.
[Int] means a list of integers. It can contain any possible number of
integers (including zero or infinity). [Char] means a list of characters.
Tuples, on the other hand, have a different type for each size, and each
combination of element types. For example, (5, 'x') is of type (Int,
Char), but (5, 'x', False) is of type (Int, Char, Bool). As far as the
type system is concerned, these two types are completely unrelated.
Because of this, you cannot write a function that works on any possible
size of tuple. It's impossible. (You can write a *method* that works for
any size of tuple that you've manually written a definition for, but
that's about it.)
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. Tuples are really for simple, quick things
like returning multiple results from a function, or for key/value pairs.
Stuff like that.
...and this whole explanation is a good example of the kind of thing
that's hard to explain in an interactive tutorial. ;-)
> So this means "let x = 5 in (the following expression)..."
Indeed yes.
> Now Step 7 in the original tutorial makes sense :-)
Yeah. It's simple, it's just explained badly...
>> OK, I'm going to stop now...
>
> OK I need to download the compiler if I am to actually learn any of this...
I can talk some more if you want?
But yes, this (alpha) web thingy lacks several important features:
- You can't define things and refer to them later. Each expression is
processed independently.
- You can't write multi-line definitions.
- You can't do I/O. (And the error message if you try is cryptic to say
the least!)
- You can't use all of the standard Haskell libraries, just the handful
the interpretter offers.
In a real Haskell interpretter, you can usually do stuff like
> let factorial n = product [1..n]
> let choose n k = (factorial n) / (factorial k * factorial (n - k))
> choose 3 5
In the online interpretter, you'd have to do
> let factorial n = product [1..n]; choose n k = (factorial n) /
(factorial k * factorial (n - k)) in choose 3 5
This, coupled with the horrifyingly buggy command history, is just no
fun at all.
Are you actually interested enough to want to play with it more?
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Darren New wrote:
> Invisible wrote:
>> I do, but it can only serve static HTML.
>
> Uh, no. Every major OS comes with a real web server.
Really?
> But if you're actually going to get into AJAX programming, you're going
> to have to learn more than you can by asking people here to explain it
> to you. ;-)
No, I'd just like to see if I can do a small proof-of-concept thing and
make it work. ;-) Let's face it, DOM is way too hard in the first place...
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
|
|