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

自闭症网瘾萝莉.ら 提交于 2021-01-26 09:35:27

问题


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?


回答1:


Use kind!.

:kind! WeirdFamily (Bool, (Char, ()))
WeirdFamily (Bool, (Char, ())) :: *
= (Bool, (Char, Int))



回答2:


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?



来源:https://stackoverflow.com/questions/62979361/is-it-possible-to-display-the-results-of-applying-a-haskell-type-family-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!