No subject


Wed Apr 10 17:18:51 CEST 2013


    snd $ fn' (zip [x] [a]) = fn [a]

I can see ways of doing this by altering fn, or by repeating some of fn in
the definition of fn', or (because in this case I know that if fn xs = x,
fn is returning the first x in xs and not any others), by doing something
nasty like:

  fn' xs = xs !! fromMaybe 0 (findIndex (\(_,a) -> a == fn (snd $ unzip
xs)) xs )

But it seems to me like there should be prettier solutions to this (that *do
not* involve changing the definition of fn). After all, this doesn't seem
like a rare pattern.

Anyone know if in fact there's a better way to go about it?

--f46d042de425749bab04dcc4c06b
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div style><span style=3D"font-family:arial,sans-serif;fon=
t-size:13px">(For some reason my previous post seems to have been truncated=
.)</span></div><span style=3D"font-family:arial,sans-serif;font-size:13px">=
<div>
<span style=3D"font-family:arial,sans-serif;font-size:13px"><br></span></di=
v>I have a function that, simplifying a little, looks like this:</span><div=
 style=3D"font-family:arial,sans-serif;font-size:13px"><br></div><div style=
=3D"font-family:arial,sans-serif;font-size:13px">
=A0 fn :: [a] -&gt; a</div><div style=3D"font-family:arial,sans-serif;font-=
size:13px">=A0 fn =3D (head .) . takeWhile $ (\_ -&gt; True)</div><div styl=
e=3D"font-family:arial,sans-serif;font-size:13px"><br></div><div style=3D"f=
ont-family:arial,sans-serif;font-size:13px">


More information about the Beginners mailing list