
Gene A wrote:
On 8/19/06, Brian Hulley
wrote: {... magSquared v = v.x*v.x + v.y*v.y + v.z*v.z ...} Hi, Won't the use of the "dot" lend confusion to the eye of the beholder.. that as in the code fragment about that v.y or v.z is implying function composition .... I'll admit to being pretty new to Haskell, but that is what it would look like to me. Could, I think cause some confusion to others reading a program with this construct, and might fool some of the tools that some others have mentioned.. Would seem that parser could or would make that mistake?
Hi Gene, In v.x or v .x then ".x" is a single lexeme, whereas in v . x or v. x the "v" and "x" are ids and the "." is a symbol. In other words, the parser sees: v.x [VarId, DottedField] v .x [VarId, DottedField] v. x [VarId, VarSym, VarId] v . x [VarId, VarSym, VarId] This works because the lexer just obeys the "maximal munch" rule ie reading from left to right eating up as many characters as possible to form each lexeme. It's probably slightly confusing when seen as plain text, but if you used an editor that fontifies VarId's differently from DottedField's, the difference would be easily visible. I think it would also become quite natural just as we already have: 123.42 vs 123 . 42 A.B.C.p vs A.B.C . p As you pointed out "f.g" at the moment means function composition. However there seems afaics to be an informal convention that spaces are always placed around the dot when used as an operator, since of course "F.g" means "the g in module F" as opposed to "F . g". Therefore my proposal is not entirely backwards compatible, though there could perhaps be a compiler flag to prevent old code from being broken, or a tool to insert the required spaces into old code. Best regards, Brian. -- Logic empowers us and Love gives us purpose. Yet still phantoms restless for eras long past, congealed in the present in unthought forms, strive mightily unseen to destroy us. http://www.metamilk.com