Here's yet another version:
> (//) :: [a] -> [b] -> [(a,b)]
> xs//ys = concat ([zip xs (reverse ys') | ys' <- inits ys] ++
> [zip xs' (reverse ys) | xs' <- tails (tail xs)])
(It only tries to reverse ys if the first comprehension comes to the end
of ys.)
This has reasonable beh
Hi all,
since I have gotten into the habit to relate proposed diagonalisation
function, I will not resist this time, either ;-)
Koen Claessen <[EMAIL PROTECTED]> writes:
>
> as // bs = diag [] [ [ (a,b) | a <- as] | b <- bs ]
>
> diag current []
Hi all,
How nice to see that my mail from July 11 generated so many different
diagonalization functions without using integers!
I saw Wolfram's reply with his interesting programming challenge but I
went on a holiday straight after that, so I could not participate in the
flood of messages that f
"the next member of the diagonalisation of the remaining dimensions"
is guaranteed to exist. Things which can prevent this are:
- An empty coordinate list in any dimension.
- Only finitely many dimensions with 2 or more coordinates each, e.g.
[0..] : repeat [0]
Regards,
Tom
Hi,
you write (message from Tom Pledger on Thu, 15 Jul 1999 13:33:06 +1200 (NZT))
(and I hope you do not mind that I send this response to the list, too):
>
> Someone was saying that my diag function ran out of space, but I've
> lost track of the message. Was it yours?
>
Yes, it was mine.
Jón Fairbairn <[EMAIL PROTECTED]> writes:
>
> > diagonalise:: [[a]] -> [a]
> > diagonalise l = d [] l
>
>
> > d [] [] = []
> > d acc [] = -- d [] acc would do, but muddles the order;
> >heads acc ++ d (rests acc) []
> > d ls (l1:rest) = heads (ls') ++ d (rests ls') rest
Stefan Kahrs <[EMAIL PROTECTED]> writes:
> I liked Mark's version, but let me add a related challenge.
>
> I defined a translation of //-list comprehensions
> that is analogous to the foldr-translation of list comprehensions
> (which optimises the map-concat approach) but works in the infin
I liked Mark's version, but let me add a related challenge.
I defined a translation of //-list comprehensions
that is analogous to the foldr-translation of list comprehensions
(which optimises the map-concat approach) but works in the infinite case
as well.
This requires an operator foldrinf, o
Another alternative to diag [[f x y | x < - xs] | y <- ys] is
to write it as diagWith f xs ys where:
diagWith f [] ys = []
diagWith f xs [] = []
diagWith f (x:xs) ys = d [x] xs ys
where
d xs' xs ys = zipWith f xs' ys ++ d' xs ys
where
d' [] [] = []
d' [] (y:ys)