[Haskell-cafe] Typeclass question

Jake McArthur jake at pikewerks.com
Sat Dec 27 16:03:34 EST 2008


Andrew Wagner wrote:
> Hmm, I actually simplified my problem too much. What I actually want is:
> data Foo a = forall a. Bar a => Foo a Bool
> 
> ...except I want the 'a' on the left to match the 'a' on the right, so 
> that you can only construct values out of values of the parameterized 
> type, which also must be of the Bar class.

Well, you can ignore my previous contribution to this thread anyway. I 
failed to see the numerous other responses suggesting the same thing.

I recommend against what you are wanting to do. It is probably nicer to 
have something like this:

     data Foo a = Foo a Bool -- don't export this

     foo :: Bar a => a -> Bool -> Foo a -- export this
     foo = Foo

You can also use GHC's new ViewPatterns extension if you would still 
like to be able to pattern match on Foo values in other modules and 
don't mind being restricted to more recent versions of GHC.

- Jake


More information about the Haskell-Cafe mailing list