I have a function, dir_con :: (Int -> Dir)
I want to pattern match to find which specific constructor dir_con is. The data type is:
data Dir = Define Int
| Equals Int
| Data Int
| LCset Int
| NoArg Int
So, dir_con will either be Define, Equals etc. It is passed to a function and I want to pattern match like so:
case dir_con of
NoArg -> Do something specific
_ -> Do something for the rest
The compiler doesn't like that. Error message is Couldn't match expected type 'Int -> Dir' with actual type 'Dir'
.
Surely NoArg
is a constructor of type (Int -> Dir)
? Does Haskell not allow this type of pattern match? I have to do this because the Dir
constructors come from a map. Is there a suggestion on how I can treat NoArg
differently?
data Dir = Dir DirType Int; data DirType = Define | Equals | Data | LCset | NoArg
. – hammar