<div dir="ltr">I wouldn't expect that to work any more than I would expect a normal function to be able to produce <font face="monospace">Int</font> or <font face="monospace">String</font> on demand, absent dependent types.</div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Sat, Apr 5, 2025 at 6:51 PM Zoran Bošnjak <<a href="mailto:zoran.bosnjak@via.si">zoran.bosnjak@via.si</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Dear haskellers,<br>
is it possible to write a type/kind level function that returns types of <br>
different kinds for different inputs. Either by using open/closed type <br>
families, a typeclass, extensions or any other type level magic. <br>
Something like this:<br>
<br>
{-# LANGUAGE DataKinds #-}<br>
{-# LANGUAGE TypeFamilies #-}<br>
<br>
import GHC.TypeLits<br>
<br>
data A = A1 | A2<br>
data B = B1 | B2<br>
<br>
type family F (n :: Nat) where<br>
F 0 = 'A1<br>
F 1 = 'A2<br>
F 2 = 'B1<br>
F 3 = 'B2<br>
<br>
The problem with this approach is that (F 0) and (F 1) are ok, but not <br>
in combination with (F 2). The error says:<br>
• Expected kind ‘A’, but ‘'B1’ has kind ‘B’<br>
<br>
If I instead write:<br>
type family F (n :: Nat) :: k where<br>
... I get compile error already on the (F 0) line<br>
• Expected kind ‘k’, but ‘'A1’ has kind ‘A’<br>
<br>
Any ideas how to remove the "same kind" restriction or how to workaround <br>
it?<br>
<br>
I am using ghc 9.6.6.<br>
<br>
regards,<br>
Zoran<br>
_______________________________________________<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><div><br clear="all"></div><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>brandon s allbery kf8nh</div><div><a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a></div></div></div></div></div>