
Cristian Baboi wrote:
On Tue, 18 Dec 2007 10:29:43 +0200, Miguel Mitrofanov
wrote: What I should have been told about upfront: - the syntax for an expression - the syntax for a block
Don't see your point.
The point is the syntax is introduced as transformation of layout form to non layout form. As a user, I just want to be able to spot the basic components of a source file without thinking about transformation rules.
Well, a "block" isn't really a unified syntactic unit. The layout rule is used for do {} expressions, which context they are expression syntax, but also in module, let, and where declarations in which context they are declaration syntax, and case expressions in which case they are, well, case alternatives; a little like declarations, I suppose. Since layout is optional, it's often defined simply by the translation into explicit {} and ;. On the other hand, if there are specific areas of ambiguity which have confused you let us know, and we'll clarify.
- the adhoc syntax rules (how to distinguish among a tuple and a pharanthesized expression and how to find the start and end of a block for example )
Oh, that's pretty easy, parenthesized expression is not divided by a comma.
Thanks! What is the end of a block ? What introduce new blocks ?
I'm not sure what you mean by a block here, so I find it hard to answer that. The end of a layout block is when a line is indented less than the first line of the layout.
Is this legal (`plus`) x y ?
No.
It's this a tuple ? ([a,b,c,d ]) ?
No, that's a list of four elements, in some parentheses which, in this context, make no semantic difference. An expression in parentheses is one of two things: (a) a tuple, if it is of the form (X,Y,Z,...) where the , are understood to be at the "top level" syntactically (b) a simple expression which has been parenthesised just to aid clarity or achieve correct precedence.
- what guarantees are made by the LANGUAGE that an IO action (such as do putStrLn "Hello world" ) is not performed twice
There are no such guarantees. If you write
a = putStrLn "Hello world" main = do {a; a;}
then your putStrLn would be performed twice. IO actions are first-class values, that's a feature, not a bug.
What guarantees that by running the main, the string "Hello world" will be printed exactly twice ?
The semantics of IO, and the guarantees of the runtime. IO specifies that (>>) means "compose two actions to make a larger action which does the first actions, then the second action". [do {a; a;} is notation for a >> a] The RTS specifies that the "main" action is performed exactly once.
- the lambda expressions can be written (input) but cannot be printed (output)
Yes, since two different lambda expressions can denote the same function. I just want the sistem to be able to print one of these expressions !
Its this too much to ask ? I find it very strange that I can write a lambda expresion, but the system cannot.
Haskell doesn't contain a code representation natively. It is not a "homoiconic" language. Just like C, C++, Java, Python, Perl, and Ruby, the compiler/interpreter is free to transform code into some more efficient form for running (including transformation all the way to native code, which is what ghc does) and once it has done so, it retains no information about the "shape of" the source code which yielded the function. Jules