[Haskell-cafe] Selda: confused about type signtures
tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Sun Apr 22 19:18:33 UTC 2018
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.
More information about the Haskell-Cafe