<div dir="ltr">Pardon, delete my code. I rushed the answer without reading carefully, my bad.</div><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 7 Aug 2019 at 13:05, Paolino <<a href="mailto:paolo.veronelli@gmail.com" target="_blank">paolo.veronelli@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">So about the type error, the second element of the tuple has no defined type. You can fix it substituting (pure v) with [v] if you want a list there.<div><br></div><div>Also </div><div><br></div><div>- chkDup ns = any (`elem` ns) </div><div>- use Set.member to reduce complexity<br></div><div><br></div><div>Best</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 7 Aug 2019 at 11:53, Dušan Kolář <<a href="mailto:kolar@fit.vut.cz" target="_blank">kolar@fit.vut.cz</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u>
<div style="font-family:monospace;font-size:10pt;font-weight:400;font-style:normal">
<p style="margin:0px;text-indent:0px">Dear Café,</p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px"> I'm trying to solve a couple of examples and exercises just for me. I've come to the point, when I'm trying working code manipulating lists rewrite to work on Foldable (etc.).</p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px"> Nevertheless, I must be doing some mistake, overlooking something, as simple code like this:</p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">chkDup [] = False</p>
<p style="margin:0px;text-indent:0px">chkDup (0:ns) = chkDup ns</p>
<p style="margin:0px;text-indent:0px">chkDup (n:ns) = elem n ns || chkDup ns</p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">which works fine, type-checks, can be used within other code, I'm trying to replace with more generic, but probably less efficient and wrong code:</p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">chkDup ns = fst $ foldr f (False,mempty) ns</p>
<p style="margin:0px;text-indent:0px"> where</p>
<p style="margin:0px;text-indent:0px"> f _ res@(True,_) = res</p>
<p style="margin:0px;text-indent:0px"> f v res@(_,vs) = if v==0 then (False, vs) else (elem v vs, pure v <> vs)</p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">which does not even type-check.</p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">Nevertheless, the error message is not too helpful, searching the Internet just confirms it's wrong and that adding AllowAmbiguousTypes would not work. The error message is:</p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">helper.hs:49:1: error:</p>
<p style="margin:0px;text-indent:0px"> • Could not deduce (Foldable f0)</p>
<p style="margin:0px;text-indent:0px"> from the context: (Eq a, Num a, Foldable t, Foldable f,</p>
<p style="margin:0px;text-indent:0px"> Applicative f, Monoid (f a))</p>
<p style="margin:0px;text-indent:0px"> bound by the inferred type for ‘chkDup’:</p>
<p style="margin:0px;text-indent:0px"> forall a (t :: * -> *) (f :: * -> *).</p>
<p style="margin:0px;text-indent:0px"> (Eq a, Num a, Foldable t, Foldable f, Applicative f,</p>
<p style="margin:0px;text-indent:0px"> Monoid (f a)) =></p>
<p style="margin:0px;text-indent:0px"> t a -> Bool</p>
<p style="margin:0px;text-indent:0px"> at helper.hs:(49,1)-(53,80)</p>
<p style="margin:0px;text-indent:0px"> The type variable ‘f0’ is ambiguous</p>
<p style="margin:0px;text-indent:0px"> • In the ambiguity check for the inferred type for ‘chkDup’</p>
<p style="margin:0px;text-indent:0px"> To defer the ambiguity check to use sites, enable AllowAmbiguousTypes</p>
<p style="margin:0px;text-indent:0px"> When checking the inferred type</p>
<p style="margin:0px;text-indent:0px"> chkDup :: forall a (t :: * -> *) (f :: * -> *).</p>
<p style="margin:0px;text-indent:0px"> (Eq a, Num a, Foldable t, Foldable f, Applicative f,</p>
<p style="margin:0px;text-indent:0px"> Monoid (f a)) =></p>
<p style="margin:0px;text-indent:0px"> t a -> Bool</p>
<p style="margin:0px;text-indent:0px"> |</p>
<p style="margin:0px;text-indent:0px">49 | chkDup ns =</p>
<p style="margin:0px;text-indent:0px"> | ^^^^^^^^^^^...</p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">So is there a nicer and working way, how to change my simple example? Is there a way, how to make it compile? Or is it useless to do that, original function is just fine...</p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">Best regards,</p>
<p style="margin:0px;text-indent:0px">Dušan</p>
<p style="margin:0px;text-indent:0px"> </p></div>_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail-m_7314868639914780348gmail-m_8607026394982793080gmail_signature"><div dir="ltr"><br><span style="font-family:sans-serif;font-size:13px">Paolo Veronelli (</span><a href="mailto:paolo.veronelli@gmail.com" style="color:rgb(17,85,204);font-family:sans-serif;font-size:13px" target="_blank">paolo.veronelli@gmail.com</a><span style="font-family:sans-serif;font-size:13px">)</span><div style="font-family:sans-serif;font-size:13px"><br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><i><font size="1">Functional developer @ <a href="http://global.de/" style="color:rgb(17,85,204)" target="_blank">global.de<br></a></font></i><font size="1"><img src="https://docs.google.com/uc?export=download&id=1c0SmOCkvvxtcGfMUBuMSzZiw91Mz02ft&revid=0Bwy_Q63_DXdOMVdndFhsWmxSTWFRTHF0QXduNTRnbEI2WnFrPQ" width="96" height="48"></font></blockquote></div></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail-m_7314868639914780348gmail_signature"><div dir="ltr"><br><span style="font-family:sans-serif;font-size:13px">Paolo Veronelli (</span><a href="mailto:paolo.veronelli@gmail.com" style="color:rgb(17,85,204);font-family:sans-serif;font-size:13px" target="_blank">paolo.veronelli@gmail.com</a><span style="font-family:sans-serif;font-size:13px">)</span><div style="font-family:sans-serif;font-size:13px"><br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><i><font size="1">Functional developer @ <a href="http://global.de/" style="color:rgb(17,85,204)" target="_blank">global.de<br></a></font></i><font size="1"><img src="https://docs.google.com/uc?export=download&id=1c0SmOCkvvxtcGfMUBuMSzZiw91Mz02ft&revid=0Bwy_Q63_DXdOMVdndFhsWmxSTWFRTHF0QXduNTRnbEI2WnFrPQ" width="96" height="48"></font></blockquote></div></div></div>