On 27 July 2011 10:45, Sergiy Nazarenko <[email protected]> wrote:
> Hi everyone!
Hi,

> I have data declaration like this:
> I try to use typeclasses,
> class GetRow a where
>    hasID :: Int -> IO a
> instance GetRow MyTableOne where
>    hasID myid = return [(MyTableOne 1 "name")]
> instance GetRow MyTableTwo where
>    hasID myid = return [(MyTableTwo 1 "name" "path")]

The issue here seems to be that you are trying to define a class
instance for /constructors/, not types.

I don't really understand what it is you are trying to do, but perhaps you
could treat MyTableOne and MyTableTwo as distinct types.
Something like:

\begin{code}
data MyTableOne = MyTableOne Int String
data MyTableTwo = MyTableTwo Int String String

instance GetRow MyTableOne where ...

instance GetRow MyTableTwo where ...
\end{code}

You might even use a class for tables, so you can define arbitrary
table structures which all support a common interface (e.g., row fetching).

Hope this helps.

Regards,
Joachim

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to