this is a follow-up
I think the use of -
, GHC can warn against non-complete patterns I'm thinking that by default this is not compile-time error, because it is always possible to clearly define partial functions:
f :: [a] - & gt; [B] - & gt; F (_: xs) (_: ys) = length xs + length ys
"undefined for empty ar" f _ [] = "error" The question is not geckel-specific. / P>
Is it ...
- Anyone wanted to apply Haskell Compiler for this kind of analysis?
- A non-complete pattern Search can not get anything but all cases?
- Partially defined work is considered legitimate and often does not apply to the type of construction shown above If this is the case, can you explain to me why the non-perfect patterns are useful / valid?
There are cases where you have no problem that a pattern matching is unattainable. For example, although this can not be optimal implementation, I do not think it will be helpful If it did not compile:
fac 0 = 1 fac n | N> 0 = n * fac (n-1)
this non -s Complete (negative number does not matter for the general use of any does not match the case) the factual act.
Additionally, it may not be possible to decide for the compiler if a pattern matching is complete:
mod2 :: integer - & gt; Integer mode 2n | Even n = 0 mod2 n | Weird N = 1
All cases should be covered here, but the compiler might not be able to detect it. Since guards can be irregularly complex, the compiler can not always determine whether patterns are perfect or not. Of course this example would be better written by otherwise
, but I think it should be compiled in its present form as well.
Comments
Post a Comment