
On Sun, Apr 22, 2018 at 08:21:11PM +0200, Marc Busqué wrote:
If I add `FlexibleContexts` and `AllowAmbiguosTypes` extensions, I can compile the program and ask for the type of `list`:
``` :t list --- list --- :: (selda-0.1.12.1:Database.Selda.Compile.Result --- (selda-0.1.12.1:Database.Selda.Column.Cols s a), --- selda-0.1.12.1:Database.Selda.Column.Columns --- (selda-0.1.12.1:Database.Selda.Column.Cols s a)) => --- selda-0.1.12.1:Database.Selda.Table.Table a --- -> IO --- [selda-0.1.12.1:Database.Selda.Compile.Res --- (selda-0.1.12.1:Database.Selda.Column.Cols s a)] ```
However, manually adding this same type:
``` list :: (Result (Cols s a), Columns (Cols s a)) => Table a -> IO [Res (Cols s a)] list table = withDB $ query (select table) ```
results in a compilation error:
Unless I am much mistaken `Cols s a` is just `a`[1,2]. That explains why the type is ambiguous. There's nothing that fixes `s`.
But I'm not sure about how I could fix that. At the end of the article it is said that this only happen in programs that "they could never really work". But, if I'm not missing something, that function does work. I have tried it with the auto-inferred signature way and it indeed can list rows for different database tables.
Can you show us a minimal example of `list` working? I'm quite confused about how it could work. Tom [1] https://www.stackage.org/haddock/lts-9.14/selda-0.1.11.1/src/Database.Selda....) [2] https://www.stackage.org/haddock/lts-9.14/selda-0.1.11.1/Database-Selda.html...