haskell - Pattern matching identical values -
I was wondering if functional programming languages (Hassel / F # / lotus).
Just think about the following example:
plus aa = 2 * a plus ab = a + b
the first version Will be called when the function is applied with two equal values (which are stored in a
).
A more useful application would be (Simplification) an AST).
simple (add AA) = multi 2 one
but Haskell rejects these codes and gives me the for conflicting definitions Warning A
- To know whether the function gets the same value or not, I have a clear case / if-check to indicate whether there is a move to indicate that one variable Against that I want to match which will happen many times?
This is called an nonlinear pattern about it's Haskel cafe mailing list But there are many threads, not long ago. Two below:
Bottom row: Applying is not impossible, but for simplicity a decision has been taken against it.
By the way, you do not need to work around if
or case
; To use a guard (a little bit) cleaner is the way:
one plus' b. A == B = 2 * A. Otherwise = A + b
Comments
Post a Comment