No subject


Wed Apr 10 17:18:51 CEST 2013


=3D fn [a]<br>


&gt;<br>&gt; I can see ways of doing this by altering fn, or by repeating s=
ome of<br>&gt; fn in the definition of fn&#39;, or (because in this case I =
know that if<br>&gt; fn xs =3D x, fn is returning the first x in xs and not=
 any others), by<br>


&gt; doing something nasty like:<br>&gt;<br>&gt; =A0 fn&#39; xs =3D xs !! f=
romMaybe 0 (findIndex (\(_,a) -&gt; a =3D=3D fn (snd $<br>&gt; unzip xs)) x=
s )<br>&gt;<br>&gt; But it seems to me like there should be prettier soluti=
ons to this<br>


&gt; (that do not involve changing the definition of fn). After all, this<b=
r>&gt; doesn&#39;t seem like a rare pattern.<br>&gt;<br>&gt; Anyone know if=
 in fact there&#39;s a better way to go about it?<br>&gt;<br>&gt;<br>&gt;<b=
r>


&gt; ------------------------------<br>&gt;<br>&gt; Message: 5<br>&gt; Date=
: Wed, 15 May 2013 14:03:56 -0400<br>&gt; From: Brent Yorgey &lt;<a href=3D=
"mailto:byorgey at seas.upenn.edu" target=3D"_blank">byorgey at seas.upenn.edu</a=
>&gt;<br>

&gt; Subject: Re: [Haskell-beginners] find by<br>
&gt; To: <a href=3D"mailto:beginners at haskell.org" target=3D"_blank">beginne=
rs at haskell.org</a><br>&gt; Message-ID: &lt;<a href=3D"mailto:20130515180356=
.GA18624 at seas.upenn.edu" target=3D"_blank">20130515180356.GA18624 at seas.upen=
n.edu</a>&gt;<br>

&gt; Content-Type: text/plain; charset=3Dus-ascii<br>
&gt;<br>&gt; On Wed, May 15, 2013 at 01:09:37PM -0400, Julian Arni wrote:<b=
r>&gt; &gt; (Truncated again - trying plain text. Sorry for the spam.)<br>&=
gt; &gt;<br>&gt; &gt; I have a function that, simplifying a little, looks l=
ike this:<br>


&gt; &gt;<br>&gt; &gt; =A0 fn :: [a] -&gt; a<br>&gt; &gt; =A0 fn =3D (head =
.) . takeWhile $ (\_ -&gt; True)<br>&gt; &gt;<br>&gt; &gt; From this, I wan=
t a function with the signature fn&#39; :: [(x,a)] -&gt;<br>&gt; &gt; (x,a)=
 such that:<br>


&gt; &gt;<br>&gt; &gt; =A0 =A0 snd $ fn&#39; (zip [x] [a]) =3D fn [a]<br>&g=
t; &gt;<br>&gt; &gt; I can see ways of doing this by altering fn, or by rep=
eating some of<br>&gt; &gt; fn in the definition of fn&#39;, or (because in=
 this case I know that if<br>


&gt; &gt; fn xs =3D x, fn is returning the first x in xs and not any others=
), by<br>&gt; &gt; doing something nasty like:<br>&gt; &gt;<br>&gt; &gt; =
=A0 fn&#39; xs =3D xs !! fromMaybe 0 (findIndex (\(_,a) -&gt; a =3D=3D fn (=
snd $<br>


&gt; &gt; unzip xs)) xs )<br>&gt; &gt;<br>&gt; &gt; But it seems to me like=
 there should be prettier solutions to this<br>&gt; &gt; (that do not invol=
ve changing the definition of fn). After all, this<br>&gt; &gt; doesn&#39;t=
 seem like a rare pattern.<br>


&gt; &gt;<br>&gt; &gt; Anyone know if in fact there&#39;s a better way to g=
o about it?<br>&gt;<br>&gt; This is not possible. =A0The problem is that gi=
ven<br>&gt;<br>&gt; =A0 fn :: [A] -&gt; A<br>&gt;<br>&gt; there is no way t=
o tell where it found the particular value of type A<br>


&gt; in the list (unless, as you say, you happen to know something extra<br=
>&gt; about the A&#39;s and how the function works). =A0And since it takes<=
br>&gt; specifically a list of type A, there is no way to give it a list wi=
th<br>


&gt; some &quot;extra&quot; information tagged onto the A&#39;s. =A0Your on=
ly option is to<br>&gt; generalize fn somehow.<br>&gt;<br>&gt; You say &quo=
t;this doesn&#39;t seem like a rare pattern&quot;; as a counterpoint, I<br>


&gt; don&#39;t think I have ever wanted it. =A0A function with the type of =
fn<br>&gt; does not seem very useful -- what should it do on the empty list=
? =A0And<br>&gt; why not just use something like &#39;find&#39; directly?<b=
r>


&gt;<br>&gt; -Brent<br>&gt;<br>&gt;<br>&gt;<br>&gt; -----------------------=
-------<br>&gt;<br>&gt; Message: 6<br>&gt; Date: Wed, 15 May 2013 23:34:09 =
+0530<br>&gt; From: irfan hudda &lt;<a href=3D"mailto:huddairfan at gmail.com"=
 target=3D"_blank">huddairfan at gmail.com</a>&gt;<br>


&gt; Subject: [Haskell-beginners] HLint fails to give suggestions<br>&gt; T=
o: <a href=3D"mailto:beginners at haskell.org" target=3D"_blank">beginners at has=
kell.org</a><br>&gt; Message-ID:<br>&gt; =A0 =A0 =A0 =A0 &lt;<a href=3D"mai=
lto:CAC5dnm6VqeC-hHSGMKZjV0bz6LVo5hr7dE5BEUWLCafVNyBbqw at mail.gmail.com" tar=
get=3D"_blank">CAC5dnm6VqeC-hHSGMKZjV0bz6LVo5hr7dE5BEUWLCafVNyBbqw at mail.gma=
il.com</a>&gt;<br>


&gt; Content-Type: text/plain; charset=3D&quot;iso-8859-1&quot;<div><div cl=
ass=3D"h5"><br>&gt;<br>&gt; I install HLint via cabal (output <a href=3D"ht=
tp://hpaste.org/88021" target=3D"_blank">http://hpaste.org/88021</a>)<br>&g=
t; To check if it was working I used following code<br>


&gt;<br>&gt; fun1 :: Int -&gt; String<br>&gt; fun1 1 =3D &quot;hell&quot;<b=
r>&gt; fun1 2 =3D 3<br>&gt;<br>&gt; and ran HLint on it<br>&gt; $ ~/.cabal/=
bin/hlint hlint_test.hs<br>&gt; No suggestions<br>&gt;<br>&gt; and it ouput=
s no suggestions<br>


&gt; any ideas?<br>&gt;<br>&gt; Additionally<br>&gt; $ ~/.cabal/bin/hlint -=
v<br>&gt; HLint v1.8.45, (C) Neil Mitchell 2006-2012<br></div></div>&gt; --=
------------ next part --------------<br>&gt; An HTML attachment was scrubb=
ed...<br>


&gt; URL: &lt;<a href=3D"http://www.haskell.org/pipermail/beginners/attachm=
ents/20130515/5b3396f0/attachment-0001.htm" target=3D"_blank">http://www.ha=
skell.org/pipermail/beginners/attachments/20130515/5b3396f0/attachment-0001=
.htm</a>&gt;<br>


&gt;<br>&gt; ------------------------------<br>&gt;<br>&gt; Message: 7<br>&=
gt; Date: Wed, 15 May 2013 11:08:23 -0700<br>&gt; From: Darren Grant &lt;<a=
 href=3D"mailto:dedgrant at gmail.com" target=3D"_blank">dedgrant at gmail.com</a=
>&gt;<br>

&gt; Subject: Re: [Haskell-beginners] HLint fails to give suggestions<br>
&gt; To: The Haskell-Beginners Mailing List - Discussion of primarily<br>&g=
t; =A0 =A0 =A0 =A0 beginner-level topics related to Haskell &lt;<a href=3D"=
mailto:beginners at haskell.org" target=3D"_blank">beginners at haskell.org</a>&g=
t;<br>&gt; Message-ID:<br>


&gt; =A0 =A0 =A0 =A0 &lt;CA+9vpFfAzxVF4v_fF-EKi=3D<a href=3D"mailto:Bq9SBVS=
ajQucuiS_AfBebfb3sqsw at mail.gmail.com" target=3D"_blank">Bq9SBVSajQucuiS_AfB=
ebfb3sqsw at mail.gmail.com</a>&gt;<br>&gt; Content-Type: text/plain; charset=
=3D&quot;iso-8859-1&quot;<div class=3D"im">
<br>

&gt;<br>&gt; Were you expecting a specific suggestion?<br>&gt;<br>&gt;<br>&=
gt;<br>&gt; On Wed, May 15, 2013 at 11:04 AM, irfan hudda &lt;<a href=3D"ma=
ilto:huddairfan at gmail.com" target=3D"_blank">huddairfan at gmail.com</a>&gt; w=
rote:<br>

&gt;<br></div><div><div class=3D"h5">
&gt; &gt; I install HLint via cabal (output <a href=3D"http://hpaste.org/88=
021" target=3D"_blank">http://hpaste.org/88021</a>)<br>&gt; &gt; To check i=
f it was working I used following code<br>&gt; &gt;<br>&gt; &gt; fun1 :: In=
t -&gt; String<br>


&gt; &gt; fun1 1 =3D &quot;hell&quot;<br>&gt; &gt; fun1 2 =3D 3<br>&gt; &gt=
;<br>&gt; &gt; and ran HLint on it<br>&gt; &gt; $ ~/.cabal/bin/hlint hlint_=
test.hs<br>&gt; &gt; No suggestions<br>&gt; &gt;<br>&gt; &gt; and it ouputs=
 no suggestions<br>


&gt; &gt; any ideas?<br>&gt; &gt;<br>&gt; &gt; Additionally<br>&gt; &gt; $ =
~/.cabal/bin/hlint -v<br>&gt; &gt; HLint v1.8.45, (C) Neil Mitchell 2006-20=
12<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br></div></div><div class=3D"im">
&gt; &gt; _______________________________________________<br>

&gt; &gt; Beginners mailing list<br>&gt; &gt; <a href=3D"mailto:Beginners at h=
askell.org" target=3D"_blank">Beginners at haskell.org</a><br>&gt; &gt; <a hre=
f=3D"http://www.haskell.org/mailman/listinfo/beginners" target=3D"_blank">h=
ttp://www.haskell.org/mailman/listinfo/beginners</a><br>


&gt; &gt;<br>&gt; &gt;<br></div>&gt; -------------- next part -------------=
-<br>&gt; An HTML attachment was scrubbed...<br>&gt; URL: &lt;<a href=3D"ht=
tp://www.haskell.org/pipermail/beginners/attachments/20130515/f67bcf5a/atta=
chment.htm" target=3D"_blank">http://www.haskell.org/pipermail/beginners/at=
tachments/20130515/f67bcf5a/attachment.htm</a>&gt;<br>


&gt;<br>&gt; ------------------------------<div class=3D"im"><br>&gt;<br>&g=
t; _______________________________________________<br>&gt; Beginners mailin=
g list<br>&gt; <a href=3D"mailto:Beginners at haskell.org" target=3D"_blank">B=
eginners at haskell.org</a><br>

&gt; <a href=3D"http://www.haskell.org/mailman/listinfo/beginners" target=
=3D"_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
&gt;<br>&gt;<br></div>&gt; End of Beginners Digest, Vol 59, Issue 17<br>&gt=
; *****************************************<br><br></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href=3D"mailto:Beginners at haskell.org">Beginners at haskell.org</a><br>
<a href=3D"http://www.haskell.org/mailman/listinfo/beginners" target=3D"_bl=
ank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>

--001a11c365724343da04dcc61dfa--



More information about the Beginners mailing list