Re: [Haskell-cafe] (a - [b]) - [a - b] ?

2006-12-04 Thread Taral

On 12/4/06, Joachim Breitner [EMAIL PROTECTED] wrote:

\g - map (\n a - g a !! n) [1..]


I think that's about as good as it gets.

--
Taral [EMAIL PROTECTED]
You can't prove anything.
   -- Gödel's Incompetence Theorem
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] (a - [b]) - [a - b] ?

2006-12-04 Thread Nicolas Frisby

It seems there's an assumption about the range of the parameter
function and the range of the entire function. That is, I think we're
assuming that the length of the final result is the same as the length
of the result of the first function?

If I'm correct in presuming that constraint, then I think this
indicates that a more elegant solution might involve using the
lightweight-dependently-typed vectors approach. Though I can't promise
it will actually be nicer!

Nick

On 12/4/06, Joachim Breitner [EMAIL PROTECTED] wrote:

Hi,

while pondering over the four fours problem, I wondered: Is there a
function of type
(a - [b]) - [a - b]

It looks a bit like sequence when applied in the ((-) a) Monad:
sequence :: [a - b] - a - [b]
but I was looking for the other direction.

I came up with:
\g - map (\n a - g a !! n) [1..]
which has the desired type and functionality, but it looks rather
inelegant and messy. Any better ideas?

Thanks,
Joachim

--
Joachim nomeata Breitner
  mail: [EMAIL PROTECTED] | ICQ# 74513189 | GPG-Key: 4743206C
  JID: [EMAIL PROTECTED] | http://www.joachim-breitner.de/
  Debian Developer: [EMAIL PROTECTED]
___
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] (a - [b]) - [a - b] ?

2006-12-04 Thread Joachim Breitner
Hi,

Am Montag, den 04.12.2006, 13:12 -0600 schrieb Nicolas Frisby:
 It seems there's an assumption about the range of the parameter
 function and the range of the entire function. That is, I think we're
 assuming that the length of the final result is the same as the length
 of the result of the first function?

Ah, of course, I forgot to mention to say what the function should
do :-)

If we call in unsequence, the following should be true for f::(a - [b])
and v::a

f v == map (\g - g v) (unsequence f)

Let’s see if I can prove that my suggested solution is correct:

f v == map (\g - g v) (map (\n a - f a !! n) [1..])
== map ((\g - g v) . (\n a - f a !! n)) [1..]
== map ((\n - (f v !! n)) [1..]
 * here I use that map (\n - l !!n ) [1..] == l. I hope that is valid
== f v

Ok, looks good. But still, I don’t like this solution with (!!) for some
reason.

Thanks,
Joachim


 On 12/4/06, Joachim Breitner [EMAIL PROTECTED] wrote:
  Hi,
 
  while pondering over the four fours problem, I wondered: Is there a
  function of type
  (a - [b]) - [a - b]
 
  It looks a bit like sequence when applied in the ((-) a) Monad:
  sequence :: [a - b] - a - [b]
  but I was looking for the other direction.
 
  I came up with:
  \g - map (\n a - g a !! n) [1..]
  which has the desired type and functionality, but it looks rather
  inelegant and messy. Any better ideas?
 
  Thanks,
  Joachim
 
  --
  Joachim nomeata Breitner
mail: [EMAIL PROTECTED] | ICQ# 74513189 | GPG-Key: 4743206C
JID: [EMAIL PROTECTED] | http://www.joachim-breitner.de/
Debian Developer: [EMAIL PROTECTED]
  ___
  Haskell-Cafe mailing list
  Haskell-Cafe@haskell.org
  http://www.haskell.org/mailman/listinfo/haskell-cafe
 

-- 
Joachim nomeata Breitner
  mail: [EMAIL PROTECTED] | ICQ# 74513189 | GPG-Key: 4743206C
  JID: [EMAIL PROTECTED] | http://www.joachim-breitner.de/
  Debian Developer: [EMAIL PROTECTED]
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] (a - [b]) - [a - b] ?

2006-12-04 Thread David Roundy
On Mon, Dec 04, 2006 at 07:00:23PM +, Joachim Breitner wrote:
 I came up with:
   \g - map (\n a - g a !! n) [1..]
 which has the desired type and functionality, but it looks rather
 inelegant and messy. Any better ideas?

I like

sequence a2bs = (head . a2bs) : sequence (tail . a2bs)

This also makes it explicit that by golly your function had better return
an infinite list, or we're in trouble.
-- 
David Roundy
Department of Physics
Oregon State University
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] (a - [b]) - [a - b] ?

2006-12-04 Thread Matthew Brecknell
Joachim Breitner:
 here I use that map (\n - l !!n ) [1..] == l. I hope that is
 valid

map (\n - l !! n) [1..] is more like (tail l). Did you mean to use
[0..]?

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


Re: [Haskell-cafe] (a - [b]) - [a - b] ?

2006-12-04 Thread Joachim Breitner
Hi,

Am Dienstag, den 05.12.2006, 05:59 +1000 schrieb Matthew Brecknell:
 Joachim Breitner:
  here I use that map (\n - l !!n ) [1..] == l. I hope that is
  valid
 
 map (\n - l !! n) [1..] is more like (tail l). Did you mean to use
 [0..]?

Probably. I hardly use (!!), so I did not remember if it starts with 0
or 1.

Thanks for the hint,
Joachim


-- 
Joachim Breitner
  e-Mail: [EMAIL PROTECTED]
  Homepage: http://www.joachim-breitner.de
  ICQ#: 74513189
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe