Hi *^o^*,<br><br>With the following rewrite rules:<br><br><span style="font-family: courier new,monospace;">lengthOP :: (Num a, Ord a) ⇒ Bool → (a → a → Bool) → [b] → a → Bool</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">lengthOP v (⊜) []&nbsp; n = 0 ⊜ n</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">lengthOP v (⊜) xxs n = co xxs 0</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp; where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; co []&nbsp;&nbsp;&nbsp;&nbsp; c = c ⊜ n</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; co (_:xs) c | n &gt; c&nbsp;&nbsp;&nbsp;&nbsp; = co xs (c+1)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | otherwise = v</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">lenEQ = lengthOP False (==)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">lenLT = lengthOP False (&lt;)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">lenLE = lengthOP False (&lt;=)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">lenGT = lengthOP True&nbsp; (&gt;)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">lenGE = lengthOP True&nbsp; (&gt;=)</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">{-# RULES</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">-- | length</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&quot;lenEQ_LHS&quot; forall xs n.&nbsp; (length xs) == n = lenEQ xs n</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&quot;lenLT_LHS&quot; forall xs n.&nbsp; (length xs) &lt;&nbsp; n = lenLT xs n</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&quot;lenLE_LHS&quot; forall xs n.&nbsp; (length xs) &lt;= n = lenLE xs n</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&quot;lenGT_LHS&quot; forall xs n.&nbsp; (length xs) &gt;&nbsp; n = lenGT xs n</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&quot;lenGE_LHS&quot; forall xs n.&nbsp; (length xs) &gt;= n = lenGE xs n</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&quot;lenEQ_RHS&quot; forall xs n.&nbsp; n == (length xs) = lenEQ xs n</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&quot;lenLT_RHS&quot; forall xs n.&nbsp; n &lt;&nbsp; (length xs) = lenGE xs n</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&quot;lenLE_RHS&quot; forall xs n.&nbsp; n &lt;= (length xs) = lenGT xs n</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&quot;lenGT_RHS&quot; forall xs n.&nbsp; n &gt;&nbsp; (length xs) = lenLE xs n</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&quot;lenGE_RHS&quot; forall xs n.&nbsp; n &gt;= (length xs) = lenLT xs n</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">-- | genericLength</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&quot;glenEQ_LHS&quot; forall xs n.&nbsp; (genericLength xs) == n = lenEQ xs n</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&quot;glenLT_LHS&quot; forall xs n.&nbsp; (genericLength xs) &lt;&nbsp; n = lenLT xs n</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&quot;glenLE_LHS&quot; forall xs n.&nbsp; (genericLength xs) &lt;= n = lenLE xs n</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&quot;glenGT_LHS&quot; forall xs n.&nbsp; (genericLength xs) &gt;&nbsp; n = lenGT xs n</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&quot;glenGE_LHS&quot; forall xs n.&nbsp; (genericLength xs) &gt;= n = lenGE xs n</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&quot;glenEQ_RHS&quot; forall xs n.&nbsp; n == (genericLength xs) = lenEQ xs n</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&quot;glenLT_RHS&quot; forall xs n.&nbsp; n &lt;&nbsp; (genericLength xs) = lenGE xs n</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&quot;glenLE_RHS&quot; forall xs n.&nbsp; n &lt;= (genericLength xs) = lenGT xs n</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&quot;glenGT_RHS&quot; forall xs n.&nbsp; n &gt;&nbsp; (genericLength xs) = lenLE xs n</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&quot;glenGE_RHS&quot; forall xs n.&nbsp; n &gt;= (genericLength xs) = lenLT xs n</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp; #-}</span><br style="font-family: courier new,monospace;"><br>1) Is there a way to tell where &#39;length&#39; is mentioned, what is meant is for example &#39;Prelude.length&#39; or any length that works on lists?<br>
2) How can I avoid the following error messages?<br><br><span style="font-family: courier new,monospace;">module Main where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">import Data.List</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">main :: IO Int</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; print $ length (repeat 0) &gt; 200</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp; print $ 200 &lt; length (repeat 0)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; print $ genericLength (repeat 0) &gt; 200</span><span style="font-family: courier new,monospace;"> -- error</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp; print $ 200 &lt; genericLength (repeat 0) -- error</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; return 0</span><br style="font-family: courier new,monospace;">
<br>########:<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; Could not deduce (Ord i) from the context (Eq i, Num i)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; arising from a use of `lenEQ&#39; at </span>########<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; Possible fix: add (Ord i) to the context of the RULE &quot;glenEQ_LHS&quot;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; In the expression: lenEQ xs n</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; When checking the transformation rule &quot;glenEQ_LHS&quot;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">########<span style="font-family: courier new,monospace;">:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; Could not deduce (Ord a) from the context (Eq a, Num a)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; arising from a use of `lenEQ&#39; at </span>########<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; Possible fix: add (Ord a) to the context of the RULE &quot;glenEQ_RHS&quot;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; In the expression: lenEQ xs n</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; When checking the transformation rule &quot;glenEQ_RHS&quot;</span><br style="font-family: courier new,monospace;">
<br>3) What speaks for/against broad usage of such rewrite rules involving list lengths?<br><br>Best Regards,<br>Cetin Sert<br>