<div dir="ltr"><div><div>I would argue that in this case existential types actually are the correct tool. What you want to do is hide some amount of type information, which is exactly what existential types do. Then, because createTable can handle any Table a when you unwrap the Table from the existential type you can still pass it to createTable.<br><br></div>Here's a sort of mock example:<br><br>```{-# LANGUAGE TypeOperators #-}<br>{-# LANGUAGE GADTs #-}<br>{-# LANGUAGE ExistentialQuantification #-}<br>{-# LANGUAGE LambdaCase #-}<br><br>import Control.Monad (forM_)<br><br>data Table a<br><br>data a :*: b where<br> (:*:) :: a -> b -> a :*: b<br>infixr 1 :*:<br><br>type RowID = Int<br>type Text = String<br><br>categories :: Table (RowID :*: Text)<br>categories = undefined<br><br>expenses :: Table (RowID:*:Text:*:Double:*:RowID)<br>expenses = undefined<br><br>createTable :: Table a -> IO ()<br>createTable _ = return ()<br><br>data ExTable = forall a. ExTable (Table a)<br><br>main :: IO ()<br>main = forM_ [ExTable categories, ExTable expenses] (\case ExTable t -> createTable t)<br>```<br><br></div>In your example this requires more boilerplate and doesn't seem much better than [createTable categories, createTable expenses], but this provides a way to actually have a list of tables of differing types without applying createTable to them first and I think that's closer to what you were going for.<br></div><br><div class="gmail_quote"><div dir="ltr">On Sun, Apr 15, 2018 at 12:35 PM Marc Busqué <<a href="mailto:marc@lamarciana.com">marc@lamarciana.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="m_1167536032478888342gmail_signature" data-smartmail="gmail_signature">Thanks for both answers. It wasn't what I had in mind, but surely it is just that I have to get used to Haskell strong typing. Until now I think I'm used to apply DRY beyond types :)</div><div class="m_1167536032478888342gmail_signature" data-smartmail="gmail_signature"><br></div><div class="m_1167536032478888342gmail_signature" data-smartmail="gmail_signature">So, from you answers, I can conclude that there is no way to tell something like the following in a type signature: "any type build with that type operators". Isn't it?</div>
</div></div>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>