[Haskell-cafe] Checking a value against a passed-in constructor?

Dan Cook danielkcook at gmail.com
Mon Jun 1 23:39:44 EDT 2009


Hi,
(Relatively new to Haskell here ..)

So I have the following:

data MyVal =  Atom String
			| Bool Bool

And I want to do something like this

check :: (Bool -> MyVal) -> MyVal -> True
check f (f x) = True
check _ _ = False

What that means is I want to pass a MyVal constructor and a MyVal, and  
return True if the second argument was constructed with the first.   
More generally, I'd like to be able to do

genCheck :: (* -> MyVal) -> MyVal -> True
genCheck f (f x) = True
genCheck _ _ = False

So that I can pass in _any_ MyVal constructor and let the function  
just check if the second argument was constructed with the first,  
without caring which constructor it is.

What is the preferred way to do this, since neither of those functions  
compile?

Cheers,
- Dan


More information about the Haskell-Cafe mailing list