Haskell function patterns 'otherwise' -
Is there any way that I can create a function with different definitions for different methods, including the < SomeFunc (pattern2) = def2 someFunc (& lt; otherwise / all other possible values & gt;) = def3
Code>
Or if this is not possible, how can it be obtained?
Thanks in advance!
Best, Skyfather
You can use the wildcard match _ :
is just :: probably one - & gt; Bull - Here we do not care what is inside just `Just '(bus _) = true - here we do not care what this is, this is not right, so' returned 'is wrong _ = wrong For clarification, the pattern is tried in the order defined by you, so the above mentioned task is not
isJust _ = Is false (only _) = true because the _ pattern is the first match. What the compiler is actually doing is turning it internally into a case statement, so the first task
would be required x = x = x's case x - & gt; True _ - & gt; False And as we know from every other programming language, which is in existence, case statement is tried.
Comments
Post a Comment