Re: [Haskell-cafe] IO and Wash

2005-02-15 Thread Tomasz Zielonka
On Wed, Feb 16, 2005 at 04:13:04AM +, John Goerzen wrote:
> I'm trying out WASH for a project.  It looks nice, but I/O looks tricky.
> I have a database lookup, and I want to present each row as an option
> for the user.  Page 15 of the Wash user-manual.pdf has an example of
> using the abstract table to do this.  It works fine, but... if a user
> hits the submit button without selecting anything, they get a JavaScript
> message saying validation fails.  Good, that's what I want to happen.
> But when Wash tries to re-display the current form, all the data from
> the database is rendered empty.  I am using the example code almost
> verbatim.  Any ideas?

I have never used table_io. maybe there's a bug in it. Hmmm, it seems
to be conceptually wrong. The single purpose of table_io seems to be
to avoid keeping the result of an IO action in the log. But how is
WASH going to recreate it when it's needed again as in your example?

Best regards
Tomasz

-- 
Szukamy programisty C++ i Haskell'a: http://tinyurl.com/5mw4e
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Unsafe IO and Wash

2005-02-15 Thread Tomasz Zielonka
On Wed, Feb 16, 2005 at 04:33:29AM +, John Goerzen wrote:
> On a related note, Wash seems to be preserving all sorts of unnecessary
> "state" from previous screens a user visited.

You do know that the current version of WASH rebuilds the continuation
by repeating all the previous steps, don't you? Until WASH can keep the
continuations on the server, it will have to pass all those parameters.
This is necessary.

> I don't understand why it doesn't pass only the parameters to the next
> screen; that should be easily determined to be all that is necessary.

It would be, I there was a server-side continuation store.

Perhaps you don't see the whole power of continuation based approach
to web programming. I will give you an example - when I use WASH, I
often pass first-class functions to from screen to screen, for example
as a way of telling the screen what to do next (a continuation), or as
the most convenient way to do something. It would be quite difficult
to pass those functions as form parameters, so they are being rebuilt
each time from the log.

> On that same topic, I've used Wash's unsafe_io some places with no ill
> effects.

Are you sure your IO actions will always yield the same result? If so,
the you can safely use unsafe_io. Otherwise you should let was save
the result of them in the log by using io.

> (Note that this has no relationship to unsafePerformIO, which
> is a different beast entirely.)  Can anyone tell me why unsafe_io in
> Wash is unsafe, and in which situations it could blow up in my face?

If you I actions can give different results when called for the second,
third, ..., nth time.

Best regards
Tomasz

-- 
Szukamy programisty C++ i Haskell'a: http://tinyurl.com/5mw4e
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Unsafe IO and Wash

2005-02-15 Thread John Goerzen
On a related note, Wash seems to be preserving all sorts of unnecessary
"state" from previous screens a user visited.  I don't understand why it
doesn't pass only the parameters to the next screen; that should be
easily determined to be all that is necessary.

On that same topic, I've used Wash's unsafe_io some places with no ill
effects.  (Note that this has no relationship to unsafePerformIO, which
is a different beast entirely.)  Can anyone tell me why unsafe_io in
Wash is unsafe, and in which situations it could blow up in my face?

Thanks,

John

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] IO and Wash

2005-02-15 Thread John Goerzen
I'm trying out WASH for a project.  It looks nice, but I/O looks tricky.
I have a database lookup, and I want to present each row as an option
for the user.  Page 15 of the Wash user-manual.pdf has an example of
using the abstract table to do this.  It works fine, but... if a user
hits the submit button without selecting anything, they get a JavaScript
message saying validation fails.  Good, that's what I want to happen.
But when Wash tries to re-display the current form, all the data from
the database is rendered empty.  I am using the example code almost
verbatim.  Any ideas?

Thanks,
John

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Problems with building GCJNI 1.2

2005-02-15 Thread Lemmih
On Tue, 15 Feb 2005 22:33:30 +0100, Dmitri Pissarenko
<[EMAIL PROTECTED]> wrote:
> Hello!
> 
> I am trying to build GCJNI 1.2 under Windows (cygwin) with GHC 6.2.1 and Green
> Card 3.01.
> 
> I am getting following error messages when entering "make".
> 
> 
> $ make
> make -C src
> make[1]: Entering directory `/cygdrive/c/dapWork/temp/downloads/gcjni/gcjni-
> 1.2/
> src'
> gcc -MM -I/cygdrive/c/Programme/Java/jdk1.5.0/include -I./win32
> > .c_dependences
>  jniInit.c util.c || (rm -f .c_dependences ; exit 1)
> m4 JNI.m4 > JNI.hs
> m4 GCJNI.m4 > GCJNI.gc
> /cygdrive/c/Programme/GreenCard/lib/greencard-3.01/greencard-bin --target ghc 
> -
> i
> /cygdrive/c/Programme/GreenCard/lib/greencard-3.01/imports --
> libdir=/cygdrive/c/
> Programme/GreenCard/lib/greencard-3.01/ GCJNI.gc
> Warning: unable to find StdDIS along the import

Did you import Foreign.GreenCard?


-- 
Friendly,
  Lemmih
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Problems with building GCJNI 1.2

2005-02-15 Thread Dmitri Pissarenko
Hello!

I am trying to build GCJNI 1.2 under Windows (cygwin) with GHC 6.2.1 and Green
Card 3.01.

I am getting following error messages when entering "make".


$ make
make -C src
make[1]: Entering directory `/cygdrive/c/dapWork/temp/downloads/gcjni/gcjni-
1.2/
src'
gcc -MM -I/cygdrive/c/Programme/Java/jdk1.5.0/include -I./win32
> .c_dependences
 jniInit.c util.c || (rm -f .c_dependences ; exit 1)
m4 JNI.m4 > JNI.hs
m4 GCJNI.m4 > GCJNI.gc
/cygdrive/c/Programme/GreenCard/lib/greencard-3.01/greencard-bin --target ghc -
i
/cygdrive/c/Programme/GreenCard/lib/greencard-3.01/imports --
libdir=/cygdrive/c/
Programme/GreenCard/lib/greencard-3.01/ GCJNI.gc
Warning: unable to find StdDIS along the import
path: /cygdrive/c/Programme/Gree
nCard/lib/greencard-3.01/, /cygdrive/c/Programme/GreenCard/lib/greencard-
3.01/im
ports,
user error ("GCJNI.gc", proc. spec "gcJniJObjectToString", line 139:
  marshall: Don't know how to marshall (declare { jniObjRef_t * } oref in
(J
Object (foreign oref {jniFreeObjRef})))

"GCJNI.gc", proc. spec "jniGetJVMState", line 156:
  Don't know how to unmarshall ((JVM (addr vmp)),(JEnv (addr envp)))

"GCJNI.gc", proc. spec "jniGetEnv", line 160:
  Don't know how to unmarshall (JEnv (addr envp))

"GCJNI.gc", proc. spec "jniFreeVM", line 167:
  marshall: Don't know how to marshall (JVM (addr vm))

"GCJNI.gc", proc. spec "jniAddClassPath", line 181:
  marshall: Don't know how to marshall (string s)

"GCJNI.gc", proc. spec "jniAddJVMOpt", line 188:
  marshall: Don't know how to marshall (string s)

"GCJNI.gc", proc. spec "jniFindClass", line 192:
  marshall: Don't know how to marshall (JEnv (addr env))

"GCJNI.gc", proc. spec "jniIsInstanceOf", line 200:
  marshall: Don't know how to marshall (JEnv (addr env))

"GCJNI.gc", proc. spec "gcJniExceptionOccurred", line 206:
  marshall: Don't know how to marshall (JEnv (addr env))

"GCJNI.gc", proc. spec "jniExceptionDescribe", line 211:
  marshall: Don't know how to marshall (JEnv (addr env))

"GCJNI.gc", proc. spec "jniExceptionClear", line 215:
  marshall: Don't know how to marshall (JEnv (addr env))

"GCJNI.gc", proc. spec "gcJniDeleteLocalRef", line 224:
  marshall: Don't know how to marshall (declare { jniObjRef_t * } oref in
(J
Object (foreign oref {jniFreeObjRef})))

"GCJNI.gc", proc. spec "jniNewLocalRef", line 230:
  marshall: Don't know how to marshall (declare { jniObjRef_t * } lsrc in
(J
Object (foreign lsrc {jniFreeObjRef})))

"GCJNI.gc", proc. spec "jniNewGlobalRef", line 239:
  marshall: Don't know how to marshall (declare { jniObjRef_t * } loref in
(
JObject (foreign loref {jniFreeObjRef})))

"GCJNI.gc", proc. spec "jniGetStaticMethodID", line 248:
  marshall: Don't know how to marshall (declare { jniObjRef_t * } cls in
(JO
bject (foreign cls {jniFreeObjRef})))

"GCJNI.gc", proc. spec "jniGetMethodID", line 255:
  marshall: Don't know how to marshall (declare { jniObjRef_t * } cls in
(JO
bject (foreign cls {jniFreeObjRef})))

"GCJNI.gc", proc. spec "jniGetStaticFieldID", line 263:
  marshall: Don't know how to marshall (declare { jniObjRef_t * } cls in
(JO
bject (foreign cls {jniFreeObjRef})))

"GCJNI.gc", proc. spec "jniGetFieldID", line 270:
  marshall: Don't know how to marshall (declare { jniObjRef_t * } cls in
(JO
bject (foreign cls {jniFreeObjRef})))

"GCJNI.gc", proc. spec "jniNewStringUTF", line 277:
  marshall: Don't know how to marshall (JEnv (addr env))

"GCJNI.gc", proc. spec "jniNewObjectArray", line 285:
  marshall: Don't know how to marshall (JEnv (addr env))

"GCJNI.gc", proc. spec "gcJniObjToJValue", line 295:
  marshall: Don't know how to marshall (declare { jniObjRef_t * } oref in
(J
Object (foreign oref {jniFreeObjRef})))

"GCJNI.gc", proc. spec "gcJniObjFromJValue", line 304:
  marshall: Don't know how to marshall (addr jvalp)

"GCJNI.gc", proc. spec "jniPushLocalFrame", line 311:
  marshall: Don't know how to marshall (int count)

"GCJNI.gc", proc. spec "gcJniIntToJValue", line 325:
  marshall: Don't know how to marshall (int val)

"GCJNI.gc", proc. spec "gcJniIntFromJValue", line 330:
  marshall: Don't know how to marshall (addr jvalp)

"GCJNI.gc", proc. spec "gcJniFloatToJValue", line 335:
  marshall: Don't know how to marshall (float val)

"GCJNI.gc", proc. spec "gcJniFloatFromJValue", line 340:
  marshall: Don't know how to marshall (addr jvalp)

"GCJNI.gc", proc. spec "gcJniDoubleToJValue", line 345:
  marshall: Don't know how to marshall (double val)

"GCJNI.gc", proc. spec "gcJniDoubleFromJValue", line 350:
  marshall: Don't know how to marshall (addr jvalp)

"GCJNI.gc", proc. spec "gcJniBoolToJValue", line 355:
  marshall: Don't know how to marshall (bool val)

"GCJNI.gc", proc. spec "gcJniBoolFromJValue", line 360:
  marshall: Don't know how to marshall (addr jvalp)

"GCJNI.gc", proc. spec "gcJniCharToJValue", line 365:
  marshall: Don't know how to marshall (char val)

"GCJNI.

Re: [Haskell-cafe] Problems building GreenCard

2005-02-15 Thread Dmitri Pissarenko
Hello!
I could fix the problem by replacing the line
GHC_OPTS = -cpp -fglasgow-exts -fno-prune-tydecls
in file lib/Makefile by this one
GHC_OPTS = -cpp -fglasgow-exts
However, I don't know what this -fno-prune-tydecls does and whether it is
important (for using Green Card to access Java).
Best regards
Dmitri Pissarenko
--
Dmitri Pissarenko
Software Engineer
http://dapissarenko.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Problems building GreenCard

2005-02-15 Thread Dmitri Pissarenko
Hello!

I'm trying to build GreenCard 3.01 (latest release according to
http://www.haskell.org/greencard/) under Windows with cygwin and GHC 6.2.1.

I'm getting these errors:


$ make prefix=/cygdrive/c/Programme/GreenCard/ install install-pkg
make[1]: Entering directory `/cygdrive/c/dapWork/temp/downloads/greencard-
3.01/g
reencard-3.01/src'
rm -f .depend
touch .depend
ghc -M -optdep-f -optdep.depend -optdep-xFiniteMap -optdep-xPretty -recomp -O -
f
glasgow-exts Casm.lhs DIS.lhs Decl.lhs ErrMonad.lhs FillIn.lhs
FillInMonad.l
hs GCToken.lhs GreenCard.lhs Lex.lhs LexM.lhs ListUtils.lhs MarshallMonad.lhs
Na
me.lhs NameSupply.lhs Package.lhs PrettyUtils.lhs Proc.lhs Process.lhs
Target.lh
s Type.lhs Parse.hs
make[1]: Leaving directory `/cygdrive/c/dapWork/temp/downloads/greencard-
3.01/gr
eencard-3.01/src'
make[1]: Entering directory `/cygdrive/c/dapWork/temp/downloads/greencard-
3.01/g
reencard-3.01/src'
ghc -recomp -O -fglasgow-exts -c Target.lhs -o Target.o
ghc -recomp -O -fglasgow-exts -c PrettyUtils.lhs -o PrettyUtils.o
ghc -recomp -O -fglasgow-exts -c Casm.lhs -o Casm.o

Casm.lhs:544:
Warning: Pattern match(es) are overlapped
 In a case alternative: _ -> ...

Casm.lhs:577:
Warning: Pattern match(es) are overlapped
 In a case alternative: _ -> ...

Casm.lhs:616:
Warning: Pattern match(es) are overlapped
 In a case alternative: _ -> ...

Casm.lhs:631:
Warning: Pattern match(es) are overlapped
 In a case alternative: _ -> ...
ghc -recomp -O -fglasgow-exts -c ListUtils.lhs -o ListUtils.o
ghc -recomp -O -fglasgow-exts -c ErrMonad.lhs -o ErrMonad.o
ghc -recomp -O -fglasgow-exts -c Name.lhs -o Name.o
ghc -recomp -O -fglasgow-exts -c DIS.lhs -o DIS.o
ghc -recomp -O -fglasgow-exts -c Type.lhs -o Type.o
ghc -recomp -O -fglasgow-exts -c Decl.lhs -o Decl.o
ghc -recomp -O -fglasgow-exts -c FillInMonad.lhs -o FillInMonad.o
ghc -recomp -O -fglasgow-exts -c NameSupply.lhs -o NameSupply.o
ghc -recomp -O -fglasgow-exts -c FillIn.lhs -o FillIn.o
ghc -recomp -O -fglasgow-exts -c GCToken.lhs -o GCToken.o
ghc -recomp -O -fglasgow-exts -c MarshallMonad.lhs -o MarshallMonad.o
ghc -recomp -O -fglasgow-exts -c Proc.lhs -o Proc.o
ghc -recomp -O -fglasgow-exts -c LexM.lhs -o LexM.o
ghc -recomp -O -fglasgow-exts -c Lex.lhs -o Lex.o
ghc -recomp -O -fglasgow-exts   -Onot  -c Parse.hs -o Parse.o

Parse.hs:1733:
Warning: Pattern match(es) are overlapped
 In a case alternative: _ -> ...
ghc -recomp -O -fglasgow-exts -c Process.lhs -o Process.o
ghc -recomp -O -fglasgow-exts -c Package.lhs -o Package.o
ghc -recomp -O -fglasgow-exts   -cpp -DBEGIN_GHC_ONLY='-}' -DEND_GHC_ONLY='{-
' -
DBEGIN_NOT_FOR_GHC='{-' -DEND_NOT_FOR_GHC='-}' -DPURE_WIN32=0  -c GreenCard.lhs
-o GreenCard.o
ghc -c ErrorHook.c -o ErrorHook.o
ghc -recomp -O -fglasgow-exts -o greencard-bin Casm.o DIS.o Decl.o
ErrMonad.
o FillIn.o FillInMonad.o GCToken.o GreenCard.o Lex.o LexM.o ListUtils.o
Marshall
Monad.o Name.o NameSupply.o Package.o PrettyUtils.o Proc.o Process.o Target.o
Ty
pe.o Parse.o ErrorHook.o
sed < greencard.ghc.in >
greencard "s|@libdir@|/cygdrive/c/Programme/GreenCard//
lib/greencard-3.01|g"
chmod a+x greencard
install -D greencard-bin /cygdrive/c/Programme/GreenCard//lib/greencard-
3.01/gre
encard-bin
install -D greencard /cygdrive/c/Programme/GreenCard//bin/greencard
make[1]: Leaving directory `/cygdrive/c/dapWork/temp/downloads/greencard-
3.01/gr
eencard-3.01/src'
make[1]: Entering directory `/cygdrive/c/dapWork/temp/downloads/greencard-
3.01/g
reencard-3.01/lib'
../src/greencard-bin --libdir=.  Foreign/GreenCard.gc
ghc -package-name greencard -cpp -fglasgow-exts -fno-prune-tydecls   -c
Foreign/
GreenCard.hs -o Foreign/GreenCard.o -hisuf hi
ghc.exe: unrecognised flags: -fno-prune-tydecls
Usage: For basic information, try the `--help' option.
make[1]: *** [Foreign/GreenCard.o] Error 1
rm Foreign/GreenCard.hs
make[1]: Leaving directory `/cygdrive/c/dapWork/temp/downloads/greencard-
3.01/gr
eencard-3.01/lib'
make[1]: Entering directory `/cygdrive/c/dapWork/temp/downloads/greencard-
3.01/g
reencard-3.01/src'
make[1]: Nothing to be done for `install'.
make[1]: Leaving directory `/cygdrive/c/dapWork/temp/downloads/greencard-
3.01/gr
eencard-3.01/src'
make[1]: Entering directory `/cygdrive/c/dapWork/temp/downloads/greencard-
3.01/g
reencard-3.01/lib'
../src/greencard-bin --libdir=.  Foreign/GreenCard.gc
ghc -package-name greencard -cpp -fglasgow-exts -fno-prune-tydecls  -prof -c
For
eign/GreenCard.hs -o Foreign/GreenCard.p_o -hisuf p_hi
ghc.exe: unrecognised flags: -fno-prune-tydecls
Usage: For basic information, try the `--help' option.
make[1]: *** [Foreign/GreenCard.p_o] Error 1
rm Foreign/GreenCard.hs
make[1]: Leaving directory `/cygdrive/c/dapWork/temp/downloads/greencard-
3.01/gr
eencard-3.01/lib'
make: *** [install] Error 2


How can I fix them?

TIA

Dmitri Pissarenko
--
Dmitri Pissarenko
Soft

Re: [Haskell-cafe] Parsing in Haskell

2005-02-15 Thread Graham Klyne
I've used Parsec for small and more complex parsing tasks, and found it 
works well for both.

In the past, I've used parser generators (not with Haskell), but now I find 
that I prefer to express a parser directly in the main programming language 
I'm using ... that way, it's easier to "escape" the grammar and do the 
things that aren't always so easy to do within the BNF-and-stuff 
formalisms.  I find my code using Parsec is close enough to the BNF that 
the syntax production logic is easy enough to see.  A very useful feature 
of Parsec is that, within what is broadly an LL(1) parsing framework, it 
provides a controlled limited lookahead capability.

Another useful little trick I've found using Haskell+Parsec is that for an 
interpreted "little language", instead of returning a data structure 
describing the input sentence, I can return a function that can be applied 
to appropriate values to execute it directly.

#g
--
At 11:36 15/02/05 +0100, Johan Glimming wrote:
Hi
I want to implement a little algebraic specification language in Haskell, 
and I have a working C implementation available which uses yacc/flex.

What is the best way of replacing yacc/bison and (f)lex when migrating the 
project into Haskell?

Best Wishes,
Johan
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Graham Klyne
For email:
http://www.ninebynine.org/#Contact
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


RE: [Haskell-cafe] Parsing in Haskell

2005-02-15 Thread Simon Marlow
On 15 February 2005 10:36, Johan Glimming wrote:

> I want to implement a little algebraic specification language in
> Haskell, and I have a working C implementation available which uses
> yacc/flex.
> 
> What is the best way of replacing yacc/bison and (f)lex when migrating
> the project into Haskell?

There are yacc & lex equivalents for Haskell, in the form of Happy
(http://www.haskell.org/happy) and Alex (http://www.haskell.org/alex)
respectively.

Cheers,
Simon
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] What is MonadPlus good for?

2005-02-15 Thread Mark Tullsen
Here's an example:  In my paper "First Class Patterns" 
,
by defining the pattern combinators using MonadPlus, you get standard 
pattern matching with the Maybe
instance of MonadPlus and you get backtracking pattern matching with 
the [] (list) instance of MonadPlus.

- Mark
On Feb 12, 2005, at 10:08 AM, Benjamin Pierce wrote:
I have seen lots of examples that show how it's useful to make some 
type
constructor into an instance of Monad.

Where can I find examples showing why it's good to take the trouble to 
show
that something is also a MonadPlus?  (I know there are many examples of
things that *are* MonadPluses; what I want to know is why this is
interesting. :-)

Thanks,
 - Benjamin

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] What is MonadPlus good for?

2005-02-15 Thread Josef Svenningsson
On Mon, 14 Feb 2005 19:01:53 -0500, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> I was thinking more along the lines of Ralf Hinze's nondeterminism
> transformer monad:
> 
> http://haskell.org/hawiki/NonDeterminism
> 
> The relevant instance is this:
> 
> instance (Monad m) => MonadPlus (NondetT m)
> 
> That is, if m is a Monad, then NondetT m is a MonadPlus.  This is not
> true if a requirement for MonadPlus is that it include the "mzero is a
> right zero for bind" law.  Indeed, such a transformer is impossible to
> write if that law is a requirement.
> 
Ah, I see. You are quite right.

> > You claimed that monad transformers break the
> > mzero-is-right-identity-for-bind law because they can be applied to
> > IO. I say, it's not the monad transformers fault. They cannot possibly
> > be expected to repair the law if they are given a faulty monad.
> 
> IO is not a faulty monad.  It satisfies all of the laws that a monad is
> supposed to satisfy.
> 
Sloppy terminology on my side again. What I meant to say is that any
MonadPlus instance of IO is faulty if we insist on the
mzero-is-right-identity-for-bind law. I agree with you that the law
should be dropped.

Cheers,

/Josef
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Parsing in Haskell

2005-02-15 Thread Peter Simons
Johan Glimming writes:

 > What is the best way of replacing yacc/bison and (f)lex when
 > migrating the project into Haskell?

My favorite tool for writing parsers is this one:

  http://www.cs.chalmers.se/~markus/BNFC/

You give it a grammar in BNF notation, and it will generate
parsers and appropriate data structures for Haskell, C,
Java, etc. 

Peter

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Parsing in Haskell

2005-02-15 Thread Jules Bean
On 15 Feb 2005, at 10:36, Johan Glimming wrote:
Hi
I want to implement a little algebraic specification language in 
Haskell, and I have a working C implementation available which uses 
yacc/flex.

What is the best way of replacing yacc/bison and (f)lex when migrating 
the project into Haskell?

I imagine for small languages a lot of people roll their own parser, 
using the "the grammar is the program" idiom as demonstrated (for 
example) in one of the final chapters of Paulson's ML book. That's what 
I've done a couple of times in various functional languages. This 
approach is simple to write (educational, too, the first time you do 
it) but not particularly fast.

Then there is the parsec project which is a considerably more serious 
implementation of combinator based parsing.  
http://www.cs.uu.nl/~daan/parsec.html

Jules
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Point-free style

2005-02-15 Thread Daniel Fischer
Am Dienstag, 15. Februar 2005 00:42 schrieben Sie:
> On Feb 14, 2005, at 2:07 AM, Daniel Fischer wrote:
> > A question for the point-free society:
> > Is there any advantage of defining
> >
> > (.<) = (.) . (.)
> >
> > rather than
> >
> > f .< g = \x y -> f (g x y)  -- or f $ g x y ?
> >
> > Analogous question for (.) . (.) . (.) etc.
>
> Well, from the fact that you even pose the question, and
> notwithstanding wise
> remarks from Simon Marlow, I'm guessing that "out of sheer impish
> delight" or
> "to tickle the aesthetic sense the way a bump to the elbow tickles the
> funny bone"
> are not the sort of answers you're looking for :) .

No, although I appreciate them and often do things (among them point-freeing 
my code -- I've not reached mastery in that department yet) for exactly these 
reasons, what I was looking for, were reasons such as
- Oh, indeed this gives better performance,
- Well, it makes no difference in performance, but it's easier to handle for 
the compiler,
or whatever else there might be.

L'art pour l'art is great, but as Simon Marlow pointed out, it's valuable to 
write code so that you (and other people) can understand it when you read it 
some time later. And there I think that point-freeing has a tendency to 
require more extensive comments.

>
> (Note that others have since risen to the occasion in this vein. And
> remember that all
> these "dotted dots" were Jerzy's fault, not mine, and that beer was at
> hand ... .)

Why "fault"?, I find all this quite interesting.
>
> More seriously, however, the generalization to n raises some
> interesting issues.
> For surely we are tempted to something like this, in a half-imagined
> syntax
> (read the LHS as "dot sub n"):
>
>  (. _ n) = foldl1 (.) (replicate n (.))
>
> And, just as surely, we shouldn't be satisfied with the answer
> "Hindley-Milner
> don't do dat" * . Rather, we should seek out ways to extend the type
> system and
> the language so that we could make this abstraction, and others like
> it, which
> are compelling at some basic level.
>
> The point being, this generalization might not occur to us (and drive
> us to
> new heights, etc.) if we didn't express it in the more "precious" style.
>
>--  Fritz

This is the sort of reason for point-free style that I was looking for.
>
> PS: Which is not to say that the Haskell type system can't be wrenched
> (coerced,
> cajoled, gently plied with sweet whispers ...) into doing things
> *similar* to
> this, using type-level natural numbers, or perhaps
> existentially-quantified data
> constructors. I'm sure that "extreme typists" like Oleg and Ken do this
> sort of
> thing to warm up in the morning, the way other typists (the mundane
> sort) lace
> their fingers together and stretch them out before settling in to their
> 60-words-per-minute day.
>
> But perhaps someone else should post some code along these lines, lest
> Oleg and
> Ken despair too much of having wasted their efforts on us. I promise to
> try out
> a few ideas myself when I get the chance.
>
>
> * (take no offense: just a reference to the old "In Living Color"
> variety show)
I don't know that, so the pun's wasted on me, pity.

Daniel

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Parsing in Haskell

2005-02-15 Thread Johan Glimming
Hi
I want to implement a little algebraic specification language in 
Haskell, and I have a working C implementation available which uses 
yacc/flex.

What is the best way of replacing yacc/bison and (f)lex when migrating 
the project into Haskell?

Best Wishes,
Johan
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Point-free style (Was: Things to avoid)

2005-02-15 Thread Graham Klyne
[I drafted this response some time ago, but didn't send it, so apologies if 
I am re-covering old ground...]

At 09:23 10/02/05 -0500, Jan-Willem Maessen wrote:
If you're trying to avoid obscurity, why advocate point-free style?
Some time ago, I asked an experienced Haskell programmer about the extent 
to which they used point-free style in day-to-day programming, and the 
response I got was to the effect that they use point-full style a fair amount.

The ...er... point, I think, is that it is easier to reason equationally 
with point-free programs, even if the intended computation is often easier 
for mere mortals to see when named values are used.  So point-free style 
helps when trying to apply program transformation techniques, and 
translation to make greater use of point-free idioms may be a useful 
precursor to transforming a program.

Something I have noticed is that, as one gets more used to using higher 
order functions, it is often more elegant to express a computation by 
composition of functions, but in so doing one has to discard preconceived 
notions of what makes an efficient program.

I think it comes down to this: learn to be comfortable with both styles, 
and be prepared to use the one that best expressed the intended solution 
(and is easiest to understand) in any given context.

#g
--
At 09:23 10/02/05 -0500, Jan-Willem Maessen wrote:
If you're trying to avoid obscurity, why advocate point-free style?
I ask this question to be deliberately provocative; I'm not trying to 
single you out in particular.  So, to everybody: What's so great about 
point-free style?

Is it really clear or obvious what
> map . (+)
means?  Contrast this with
> \n -> map (+n)
or
> \n xs -> map (+n) xs
I submit that, while it is possible to develop a reading knowledge of 
point-free style, non-trivial use of point-free 
computations---compositions of functions with arity greater than 1, as 
above, compositions of sections of composition or application, arrow 
notation without the sugar, and so forth---will always be more difficult 
to read and understand than the direct version.  I submit that this is 
true even if one is familiar with point-free programming and skilled in 
its use.
Even something as simple as eta-reduction (as in the second and third 
functions above) can seriously obscure the meaning of program code by 
concealing the natural arity of a function.

-Jan-Willem Maessen
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Graham Klyne
For email:
http://www.ninebynine.org/#Contact
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Point-free style

2005-02-15 Thread Graham Klyne
At 09:00 11/02/05 +0100, Ketil Malde wrote:
Matthew Roberts <[EMAIL PROTECTED]> writes:
>> [Point-free] compositions of functions with arity greater than 1,
>> [...] compositions of sections of composition or application,
>> arrow notation without the sugar, and so forth---will always be more
>> difficult to read and understand than the direct version.
> I have to agree (although I suspect few others will :))
I tend to agree, also.  Type signatures help, of course.  E.g. with
the previously mentioned and rather cryptic function
(.) . (.) .(.)
I entered it into GHCi, and got
:: forall a a b c a.
  (b -> c) -> (a -> a -> a -> b) -> a -> a -> a -> c
and it suddenly is much clearer what it does.
Hmm... noting the discrepancy with HUGS mentioned later in this thread, I 
entered this into GHCi and got this:
[[
Prelude> :t (.) . (.) . (.)
(.) . (.) . (.) :: forall a a1 b c a2.
   (b -> c) -> (a -> a1 -> a2 -> b) -> a -> a1 -> a2 -> c
]]

I think you maybe dropped the digits in the type variable names?
#g

Graham Klyne
For email:
http://www.ninebynine.org/#Contact
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] RDF and stuff (was: Point-free style ...)

2005-02-15 Thread Graham Klyne
At 23:00 10/02/05 -0500, David Menendez wrote:
Here's another one:
addTriple (s,p,o) = addArc s p o . addNode s . addNode p . addNode o
It looks like you're playing around with RDF here.  A quick check of your 
web site shows a Semantic Web angle to some of your workings.   I also see 
you show up in some of the ESW work.

You may be interested that I have a full RDF/XML parser in Haskell (based 
on a modified version of HaXML) (and also a reasonably competent Notation3 
parser).It passes all of Dave Beckett's RDF parser test cases, which 
include all the W3C RDF core WG test cases, (except one to do with I18N 
handling).  I haven't yet found time to wrap it all up neatly, but the code 
is available here:

RDF/XML parser and test code:
  http://www.ninebynine.org/Software/HaskellRDF/RDF/Harp/
Supporting code for RDF node handling:
  http://www.ninebynine.org/Software/HaskellRDF/RDF/Label/
Modified HaXML parser:
  http://www.ninebynine.org/Software/HaskellUtils/HaXml-1.12/
URI parser (above should also work with library version in next GHC):
  http://www.ninebynine.org/Software/HaskellUtils/Network/
Possibly uses some other support modules from:
  http://www.ninebynine.org/Software/HaskellUtils/
I had been meaning to wrap all this into my Swish package 
(http://www.ninebynine.org/RDFNotes/Swish/Intro.html), but real work 
intervened.  I do intend to return to this when I can find an excuse to 
make it part of the new day job.

#g

Graham Klyne
For email:
http://www.ninebynine.org/#Contact
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe