[Haskell-cafe] (a -> [b]) -> [a -> b] ?
Joachim Breitner
mail at joachim-breitner.de
Mon Dec 4 14:24:53 EST 2006
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 <mail at joachim-breitner.de> 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: mail at joachim-breitner.de | ICQ# 74513189 | GPG-Key: 4743206C
> > JID: joachimbreitner at amessage.de | http://www.joachim-breitner.de/
> > Debian Developer: nomeata at debian.org
> > _______________________________________________
> > Haskell-Cafe mailing list
> > Haskell-Cafe at haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
> >
--
Joachim "nomeata" Breitner
mail: mail at joachim-breitner.de | ICQ# 74513189 | GPG-Key: 4743206C
JID: joachimbreitner at amessage.de | http://www.joachim-breitner.de/
Debian Developer: nomeata at debian.org
More information about the Haskell-Cafe
mailing list