I'm trying to translate The Little MLer into Haskell. I've got this
data Shishkebab = Skewer | Onion Shishkebab | Lamb Shishkebab | Tomato Shishkebab deriving Show
Then I have this which works
veggieKebab :: Shishkebab -> Bool
veggieKebab Skewer = True
veggieKebab (Onion (shk)) = veggieKebab shk
veggieKebab (Tomato (shk)) = veggieKebab shk
veggieKebab (Lamb (shk)) = False
> veggieKebab (Tomato (Onion (Tomato (Onion Skewer))))
True
but I'm wondering if I could do something like this
veggieKebab :: Shishkebab -> Bool
veggieKebab Skewer = True
veggieKebab (shkb (sk)) | (shkb == Onion) || (shkb == Tomato) = veggieKebab sk
| otherwise = False
This doesn't work, giving a "Parse error in pattern: shkb". I've been advised that I'm trying to treat what is a data constructor like a variable, but I can't fathom what that means in this case. What I'm trying to leverage is what I've learned from dealing with lists and recursion through the consed list. So if effect I'm trying to recurse through a consed Shishkebab object. It works in the first case, but hyow could I do this in this more generic way like the second try does?
LB