title: Use a parameter as pattern in Haskell
body: <p>Is it possible to make a generic function that would take either Foo or Bar as an argument and would return a function that uses that argument in its pattern matching?</p>
  
  <p>For instance, if I have</p>
  
  <pre><code>isFoo :: SomeData -&gt; Bool
  isFoo (Foo _) = True
  isFoo _       = False
  
  isBar :: SomeData -&gt; Bool
  isBar (Bar _) = True
  isBar _       = False
  </code></pre>
  
  <p>Is there a way to create a generic function, something like</p>
  
  <pre><code>checkType :: SomeClass -&gt; SomeData -&gt; Bool
  checkType (SomeClass _) = True
  checkType _ = False
  </code></pre>
  
  <p>I realize the situation looks a little odd, and the actual use case is a little more complex, but the problem is identical.</p>
  
  <hr>
  
  <p>The actual code I'm trying to refactor is the following</p>
  
  <pre><code>isString :: [LispVal] -&gt; ThrowsError LispVal
  isString [(String _)] = return $ Bool True
  isString ((String _):xs) = isString xs &gt;&gt;= unpackBool &gt;&gt;= return . Bool
  isString _ = return $ Bool False
  
  isSymbol :: [LispVal] -&gt; ThrowsError LispVal
  isSymbol [(Atom _)] = return $ Bool True
  isSymbol ((Atom _):xs) = isSymbol xs &gt;&gt;= unpackBool &gt;&gt;= return . Bool
  isSymbol _ = return $ Bool False
  
  isNumber :: [LispVal] -&gt; ThrowsError LispVal
  isNumber [(Number _)] = return $ Bool True
  isNumber ((Number _):xs) = isNumber xs &gt;&gt;= unpackBool &gt;&gt;= return . Bool
  isNumber _ = return $ Bool False
  </code></pre>
  
  <p>So I'd like some way to make this more dry</p>