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 (⊜) [] 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;"> where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> co [] c = c ⊜ n</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> co (_:xs) c | n > c = co xs (c+1)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> | 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 (<)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">lenLE = lengthOP False (<=)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">lenGT = lengthOP True (>)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">lenGE = lengthOP True (>=)</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;">"lenEQ_LHS" forall xs n. (length xs) == n = lenEQ xs n</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">"lenLT_LHS" forall xs n. (length xs) < n = lenLT xs n</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">"lenLE_LHS" forall xs n. (length xs) <= n = lenLE xs n</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">"lenGT_LHS" forall xs n. (length xs) > n = lenGT xs n</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">"lenGE_LHS" forall xs n. (length xs) >= 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;">"lenEQ_RHS" forall xs n. n == (length xs) = lenEQ xs n</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">"lenLT_RHS" forall xs n. n < (length xs) = lenGE xs n</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">"lenLE_RHS" forall xs n. n <= (length xs) = lenGT xs n</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">"lenGT_RHS" forall xs n. n > (length xs) = lenLE xs n</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">"lenGE_RHS" forall xs n. n >= (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;">"glenEQ_LHS" forall xs n. (genericLength xs) == n = lenEQ xs n</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">"glenLT_LHS" forall xs n. (genericLength xs) < n = lenLT xs n</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">"glenLE_LHS" forall xs n. (genericLength xs) <= n = lenLE xs n</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">"glenGT_LHS" forall xs n. (genericLength xs) > n = lenGT xs n</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">"glenGE_LHS" forall xs n. (genericLength xs) >= 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;">"glenEQ_RHS" forall xs n. n == (genericLength xs) = lenEQ xs n</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">"glenLT_RHS" forall xs n. n < (genericLength xs) = lenGE xs n</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">"glenLE_RHS" forall xs n. n <= (genericLength xs) = lenGT xs n</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">"glenGT_RHS" forall xs n. n > (genericLength xs) = lenLE xs n</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">"glenGE_RHS" forall xs n. n >= (genericLength xs) = lenLT xs n</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> #-}</span><br style="font-family: courier new,monospace;"><br>1) Is there a way to tell where 'length' is mentioned, what is meant is for example 'Prelude.length' 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;"> print $ length (repeat 0) > 200</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> print $ 200 < length (repeat 0)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> print $ genericLength (repeat 0) > 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;"> print $ 200 < genericLength (repeat 0) -- error</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> 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;"> 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;"> arising from a use of `lenEQ' at </span>########<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> Possible fix: add (Ord i) to the context of the RULE "glenEQ_LHS"</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> In the expression: lenEQ xs n</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> When checking the transformation rule "glenEQ_LHS"</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;"> 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;"> arising from a use of `lenEQ' at </span>########<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> Possible fix: add (Ord a) to the context of the RULE "glenEQ_RHS"</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> In the expression: lenEQ xs n</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> When checking the transformation rule "glenEQ_RHS"</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>