[Haskell-cafe] foreach

Bulat Ziganshin bulat.ziganshin at gmail.com
Thu Sep 14 08:36:52 EDT 2006

Hello Tim,

Wednesday, September 13, 2006, 10:48:37 PM, you wrote:

> I would like to add to this.  The previous loop runs the code
> once independantly for each item in the list.  Sometimes you want
> to carry state through the loop:

all this can be easily implemented by programmer himself. but we can't
add our own syntax constructions. so it will be great to either add
constructs that mimics existing imperative languages or a way to
redefine syntax on-the-fly. second can be implemented by using
Parsec-like parser in haskell compiler. i also seen a syntax macros
for Haskell: http://www.cs.uu.nl/groups/ST/twiki/pub/Center/SyntaxMacros/sm_example.zip

one project that adds syntax sugar for manipulating imperative arrays
and hashes is http://www.isi.edu/~hdaume/STPP/stpp.tar.gz

we can also develop some ideas that will allow user to extend language
with imperative-friendly features. first, the problem is that Haskell
requires to exactly specify order of evaluation. but in many cases
it's not important - when we want to multiply values of two variables,
it's no matter what variable will be read first. so, instead of

a' <- val a
b' <- val b
c =: a' * b'

we will prefer to write

c =: a*b

this involves a lot of problems with types and and need to redefine
classes for every operation that can be used in such way

second, we need to be able to define new keywords together with using
layout statements in our constructs:

for i in [1..n] while a[i]<0 do

may be it should be just syntax-level macro which generates code like

foreachCond [1..n] (a]i]<0) $ \i -> do

and last problem is what code to generate for break/continue (goto? :)

Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com

More information about the Haskell-Cafe mailing list