No subject
Wed Apr 10 17:18:51 CEST 2013
=3D fn [a]<br>
><br>> I can see ways of doing this by altering fn, or by repeating s=
ome of<br>> fn in the definition of fn', or (because in this case I =
know that if<br>> fn xs =3D x, fn is returning the first x in xs and not=
any others), by<br>
> doing something nasty like:<br>><br>> =A0 fn' xs =3D xs !! f=
romMaybe 0 (findIndex (\(_,a) -> a =3D=3D fn (snd $<br>> unzip xs)) x=
s )<br>><br>> But it seems to me like there should be prettier soluti=
ons to this<br>
> (that do not involve changing the definition of fn). After all, this<b=
r>> doesn't seem like a rare pattern.<br>><br>> Anyone know if=
in fact there's a better way to go about it?<br>><br>><br>><b=
r>
> ------------------------------<br>><br>> Message: 5<br>> Date=
: Wed, 15 May 2013 14:03:56 -0400<br>> From: Brent Yorgey <<a href=3D=
"mailto:byorgey at seas.upenn.edu" target=3D"_blank">byorgey at seas.upenn.edu</a=
>><br>
> Subject: Re: [Haskell-beginners] find by<br>
> To: <a href=3D"mailto:beginners at haskell.org" target=3D"_blank">beginne=
rs at haskell.org</a><br>> Message-ID: <<a href=3D"mailto:20130515180356=
.GA18624 at seas.upenn.edu" target=3D"_blank">20130515180356.GA18624 at seas.upen=
n.edu</a>><br>
> Content-Type: text/plain; charset=3Dus-ascii<br>
><br>> On Wed, May 15, 2013 at 01:09:37PM -0400, Julian Arni wrote:<b=
r>> > (Truncated again - trying plain text. Sorry for the spam.)<br>&=
gt; ><br>> > I have a function that, simplifying a little, looks l=
ike this:<br>
> ><br>> > =A0 fn :: [a] -> a<br>> > =A0 fn =3D (head =
.) . takeWhile $ (\_ -> True)<br>> ><br>> > From this, I wan=
t a function with the signature fn' :: [(x,a)] -><br>> > (x,a)=
such that:<br>
> ><br>> > =A0 =A0 snd $ fn' (zip [x] [a]) =3D fn [a]<br>&g=
t; ><br>> > I can see ways of doing this by altering fn, or by rep=
eating some of<br>> > fn in the definition of fn', or (because in=
this case I know that if<br>
> > fn xs =3D x, fn is returning the first x in xs and not any others=
), by<br>> > doing something nasty like:<br>> ><br>> > =
=A0 fn' xs =3D xs !! fromMaybe 0 (findIndex (\(_,a) -> a =3D=3D fn (=
snd $<br>
> > unzip xs)) xs )<br>> ><br>> > But it seems to me like=
there should be prettier solutions to this<br>> > (that do not invol=
ve changing the definition of fn). After all, this<br>> > doesn't=
seem like a rare pattern.<br>
> ><br>> > Anyone know if in fact there's a better way to g=
o about it?<br>><br>> This is not possible. =A0The problem is that gi=
ven<br>><br>> =A0 fn :: [A] -> A<br>><br>> there is no way t=
o tell where it found the particular value of type A<br>
> in the list (unless, as you say, you happen to know something extra<br=
>> about the A's and how the function works). =A0And since it takes<=
br>> specifically a list of type A, there is no way to give it a list wi=
th<br>
> some "extra" information tagged onto the A's. =A0Your on=
ly option is to<br>> generalize fn somehow.<br>><br>> You say &quo=
t;this doesn't seem like a rare pattern"; as a counterpoint, I<br>
> don't think I have ever wanted it. =A0A function with the type of =
fn<br>> does not seem very useful -- what should it do on the empty list=
? =A0And<br>> why not just use something like 'find' directly?<b=
r>
><br>> -Brent<br>><br>><br>><br>> -----------------------=
-------<br>><br>> Message: 6<br>> Date: Wed, 15 May 2013 23:34:09 =
+0530<br>> From: irfan hudda <<a href=3D"mailto:huddairfan at gmail.com"=
target=3D"_blank">huddairfan at gmail.com</a>><br>
> Subject: [Haskell-beginners] HLint fails to give suggestions<br>> T=
o: <a href=3D"mailto:beginners at haskell.org" target=3D"_blank">beginners at has=
kell.org</a><br>> Message-ID:<br>> =A0 =A0 =A0 =A0 <<a href=3D"mai=
lto:CAC5dnm6VqeC-hHSGMKZjV0bz6LVo5hr7dE5BEUWLCafVNyBbqw at mail.gmail.com" tar=
get=3D"_blank">CAC5dnm6VqeC-hHSGMKZjV0bz6LVo5hr7dE5BEUWLCafVNyBbqw at mail.gma=
il.com</a>><br>
> Content-Type: text/plain; charset=3D"iso-8859-1"<div><div cl=
ass=3D"h5"><br>><br>> 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>
><br>> fun1 :: Int -> String<br>> fun1 1 =3D "hell"<b=
r>> fun1 2 =3D 3<br>><br>> and ran HLint on it<br>> $ ~/.cabal/=
bin/hlint hlint_test.hs<br>> No suggestions<br>><br>> and it ouput=
s no suggestions<br>
> any ideas?<br>><br>> Additionally<br>> $ ~/.cabal/bin/hlint -=
v<br>> HLint v1.8.45, (C) Neil Mitchell 2006-2012<br></div></div>> --=
------------ next part --------------<br>> An HTML attachment was scrubb=
ed...<br>
> URL: <<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>><br>
><br>> ------------------------------<br>><br>> Message: 7<br>&=
gt; Date: Wed, 15 May 2013 11:08:23 -0700<br>> From: Darren Grant <<a=
href=3D"mailto:dedgrant at gmail.com" target=3D"_blank">dedgrant at gmail.com</a=
>><br>
> Subject: Re: [Haskell-beginners] HLint fails to give suggestions<br>
> To: The Haskell-Beginners Mailing List - Discussion of primarily<br>&g=
t; =A0 =A0 =A0 =A0 beginner-level topics related to Haskell <<a href=3D"=
mailto:beginners at haskell.org" target=3D"_blank">beginners at haskell.org</a>&g=
t;<br>> Message-ID:<br>
> =A0 =A0 =A0 =A0 <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>><br>> Content-Type: text/plain; charset=
=3D"iso-8859-1"<div class=3D"im">
<br>
><br>> Were you expecting a specific suggestion?<br>><br>><br>&=
gt;<br>> On Wed, May 15, 2013 at 11:04 AM, irfan hudda <<a href=3D"ma=
ilto:huddairfan at gmail.com" target=3D"_blank">huddairfan at gmail.com</a>> w=
rote:<br>
><br></div><div><div class=3D"h5">
> > I install HLint via cabal (output <a href=3D"http://hpaste.org/88=
021" target=3D"_blank">http://hpaste.org/88021</a>)<br>> > To check i=
f it was working I used following code<br>> ><br>> > fun1 :: In=
t -> String<br>
> > fun1 1 =3D "hell"<br>> > fun1 2 =3D 3<br>> >=
;<br>> > and ran HLint on it<br>> > $ ~/.cabal/bin/hlint hlint_=
test.hs<br>> > No suggestions<br>> ><br>> > and it ouputs=
no suggestions<br>
> > any ideas?<br>> ><br>> > Additionally<br>> > $ =
~/.cabal/bin/hlint -v<br>> > HLint v1.8.45, (C) Neil Mitchell 2006-20=
12<br>> ><br>> ><br>> ><br></div></div><div class=3D"im">
> > _______________________________________________<br>
> > Beginners mailing list<br>> > <a href=3D"mailto:Beginners at h=
askell.org" target=3D"_blank">Beginners at haskell.org</a><br>> > <a hre=
f=3D"http://www.haskell.org/mailman/listinfo/beginners" target=3D"_blank">h=
ttp://www.haskell.org/mailman/listinfo/beginners</a><br>
> ><br>> ><br></div>> -------------- next part -------------=
-<br>> An HTML attachment was scrubbed...<br>> URL: <<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>><br>
><br>> ------------------------------<div class=3D"im"><br>><br>&g=
t; _______________________________________________<br>> Beginners mailin=
g list<br>> <a href=3D"mailto:Beginners at haskell.org" target=3D"_blank">B=
eginners at haskell.org</a><br>
> <a href=3D"http://www.haskell.org/mailman/listinfo/beginners" target=
=3D"_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
><br>><br></div>> End of Beginners Digest, Vol 59, Issue 17<br>>=
; *****************************************<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