Hi everyone!
I have data declaration like this:
data MyTable = MyTableOne Int String | MyTableTwo Int String String
and function that insert new row in tables:
newRow :: MyTable -> IO Int
newRow (MyTableOne fld1 fld2 ) = .....
newRow (MyTableTwo fld1 fld2 fld3 ) = ......
That work perfectly, I enjoy it. But now I want to get rows, and I don't know what to do :( I want func something like this:
getRow :: Int -> [MyTable]
.... - what should I write here ?
Possibly use this function:
getRow 23 :: MyTableTwo
(like haskell function Read for example: read "7" :: Int)
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")]
But I have error:
Not in scope: type constructor or class `MyTableOne'
make: *** [Foo.so] Error 1
Not in scope: type constructor or class `MyTableTwo'
make: *** [Foo.so] Error 1
I ask you to suggest me right way in my efforts
Cheers!