Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to display the results of applying a Haskell type family function?

For example, if I have these weird types:

{-# LANGUAGE TypeFamilies #-}
type family WeirdFamily a
type instance WeirdFamily () = Int
type instance WeirdFamily (a, b) = (a, WeirdFamily b)

Can I display (e.g. in GHCi) the result of WeirdFamily (Bool, (Char, ())) by typing something like:

:t WeirdFamily (Bool, (Char, ()))

into GHCi?

like image 793
David Avatar asked Jul 19 '20 10:07

David


2 Answers

Use kind!.

:kind! WeirdFamily (Bool, (Char, ()))
WeirdFamily (Bool, (Char, ())) :: *
= (Bool, (Char, Int))
like image 118
snak Avatar answered Nov 08 '22 02:11

snak


So I have figured out an answer. Type this into GHCi:

f :: WeirdFamily (Bool, (Char, ())); f = undefined
:t f

gives f :: (Bool, (Char, Int))

But it feels like there should be a "cleaner" way. Is there?

like image 1
David Avatar answered Nov 08 '22 03:11

David