Lets say i have a piece of code like this:
test pattern
| pattern == (_,NOT (WIRE _)) = 1
| pattern == (_,AND (WIRE _) (WIRE _)) = 2
| otherwise = 0
Where i am trying to match it against one of several possibilities, some with one (WIRE ""), some with two. I have actual input as follows e.g.: ("p",NOT (WIRE "x")). I would like to have a pattern that could accept any letter as input (what i was hoping for with the _) and am failing dismally (illegal _). Is it possible to do this in haskell?
OK, this makes a lot more sense after the edit.
==
compares values, but _
is a pattern. Patterns appear in only the following syntactic contexts:
=
", at top level or in where
blocks or in let
expressions or commands (in do
notation);<-
in do
notation or in a list comprehension;->
in a case
expression;\
) expressions.(I hope I haven't forgotten any!) In your case, you can achieve what you want by simply writing
test (_, NOT (WIRE _)) = 1
test (_, AND (WIRE _) (WIRE _)) = 2
test _ = 0
You might ask what is the correct version of "pattern == (_, NOT (WIRE _))
". Well, you can write:
case pattern of
(_, NOT (WIRE _)) -> True
_ -> False