Victor M. Gulias submitted a little frustrating problem.
This worked:
any' p xs = [x | x <- xs, p x] /= []
and the following generated a type error, unless type annotated
explicitly.
all' p xs = [x | x <- xs, p x] == xs
Victor asks:
> Any (simple) answer? (I'm afraid monad stuff, aggh)... I have
> many ML-minded students blaming at hugs because is not able to
> print the result of evaluating [] without a type annotation 8(
*********
Since then we received some responses/non-responses, for example
Tommy Thorn was shocked. Benedict R. Gaster analyzes the problem
and proposes Hugs 1.3c. Mariano Suarez Alvarez asks further
questions. Koen Claessen clarifies the answer a little differently
than BRG.
Well, I happen to teach compilation using Haskell. To students who
had *never* any experience with Haskell before. The word "simple"
for me has a very particular flavour, and although I must mention
such nasty words as 'Monad', I don't do it for pleasure.
I posed this question to a group of very "fresh" students with a
comment: this is incomplete and generates an error. Can you do
something about it? Analyse all possible cases.
I *got* an answer. They proposed to add {sth. equivalent to}
all' p [] = True
simply because they were uncertain what should be the answer in
this case...
************************************
This story is a pretext for a more general question.
Seeing that some people love comprehensions, and some have
problems with them.
That the 'do' notation need not be the best possible structure
inside a functional program.
That the explicit monadic parser chaining through ... >>= \var -> ...
makes my students nervous ...
-- Would it be possible to add to Haskell a *macro-preprocessor*?
Source->source transformations are there everywhere. Why everything
should be hidden inside the compiler?
I could define a macro [ ... | ...] linked to a restricted variant
of 'map' working with the List monad only, and avoid the frustration.
I could rewrite the CPS ...f x \v -> g y \v1 -> ... in a 'classic'
form
v <- f x
v1 <- g y ...
etc. - a useful transition from continuations to register machine.
I could be able to write parsers more comfortably, closer to BNF -
as the DCG in Prolog.
Of course, the worst thing one can do to a language is to transform
it into amoeba, but Clean has some macros and lives. Scheme could
not survive without. Obviously, we can write our own small preprocessor,
and this project is underway, but, again, introducing a non-standard,
local syntactic forms into a *known* language is methodologically
bad. Gurus, are you there?
Yours
Jerzy Karczmarczuk
University of Caen, Normandy, France.