Alejandro Serrano Mena | 20 Jul 14:45 2014
Picon

Obtaining kind of a HsType

Dear Haskell-café,
I'm trying to get some information of the kinds of types in a program. In particular, I want to obtain the kinds of arguments to type family instances, that is, given:

type family F a b :: Nat
type instance F (List k) b = b

I would like to obtain the kinds of "k" and "b" in the left-hand side of the type instance.

In particular, I'm obtaining type family instance information via LTyFamInstEqn [http://www.haskell.org/ghc/docs/latest/html/libraries/ghc/HsDecls.html#t:LTyFamInstEqn]. Inside, I get a list of binders of type HsWithBndrs [LHsType name]. I'm assuming each of the LHsTypes inside is a pattern in the type family instance. Thus, I'm looking at those elements and try to find their kind there.

Thus, the specific question is: given a HsType, can I obtain its kind somehow?

Thanks in advance
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Richard Eisenberg | 20 Jul 18:17 2014

Re: Obtaining kind of a HsType

Hi Alejandro,

It sounds like you want tc_infer_lhs_type from TcHsType. This function is not exported, but you can look around at other functions in that module to see if there's an exported one that serves your needs. You may need to convert the HsType to a Type (Type is the same as TcType, roughly) and then call typeKind.

I hope this helps!
Richard

On Jul 20, 2014, at 8:45 AM, Alejandro Serrano Mena <trupill <at> gmail.com> wrote:

Dear Haskell-café,
I'm trying to get some information of the kinds of types in a program. In particular, I want to obtain the kinds of arguments to type family instances, that is, given:

type family F a b :: Nat
type instance F (List k) b = b

I would like to obtain the kinds of "k" and "b" in the left-hand side of the type instance.

In particular, I'm obtaining type family instance information via LTyFamInstEqn [http://www.haskell.org/ghc/docs/latest/html/libraries/ghc/HsDecls.html#t:LTyFamInstEqn]. Inside, I get a list of binders of type HsWithBndrs [LHsType name]. I'm assuming each of the LHsTypes inside is a pattern in the type family instance. Thus, I'm looking at those elements and try to find their kind there.

Thus, the specific question is: given a HsType, can I obtain its kind somehow?

Thanks in advance
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Alejandro Serrano Mena | 20 Jul 19:51 2014
Picon

Re: Obtaining kind of a HsType

Is it very difficult to convert from HsType to Type?

Thanks for the information!


2014-07-20 18:17 GMT+02:00 Richard Eisenberg <eir <at> cis.upenn.edu>:
Hi Alejandro,

It sounds like you want tc_infer_lhs_type from TcHsType. This function is not exported, but you can look around at other functions in that module to see if there's an exported one that serves your needs. You may need to convert the HsType to a Type (Type is the same as TcType, roughly) and then call typeKind.

I hope this helps!
Richard

On Jul 20, 2014, at 8:45 AM, Alejandro Serrano Mena <trupill <at> gmail.com> wrote:

Dear Haskell-café,
I'm trying to get some information of the kinds of types in a program. In particular, I want to obtain the kinds of arguments to type family instances, that is, given:

type family F a b :: Nat
type instance F (List k) b = b

I would like to obtain the kinds of "k" and "b" in the left-hand side of the type instance.

In particular, I'm obtaining type family instance information via LTyFamInstEqn [http://www.haskell.org/ghc/docs/latest/html/libraries/ghc/HsDecls.html#t:LTyFamInstEqn]. Inside, I get a list of binders of type HsWithBndrs [LHsType name]. I'm assuming each of the LHsTypes inside is a pattern in the type family instance. Thus, I'm looking at those elements and try to find their kind there.

Thus, the specific question is: given a HsType, can I obtain its kind somehow?

Thanks in advance
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Richard Eisenberg | 20 Jul 19:53 2014

Re: Obtaining kind of a HsType



On Jul 20, 2014, at 1:51 PM, Alejandro Serrano Mena <trupill <at> gmail.com> wrote:

Is it very difficult to convert from HsType to Type?


This is what many of the functions in the TcHsType module do, with slight variations. Look closely in that module, and I think you'll find a solution.

Richard

Thanks for the information!


2014-07-20 18:17 GMT+02:00 Richard Eisenberg <eir <at> cis.upenn.edu>:
Hi Alejandro,

It sounds like you want tc_infer_lhs_type from TcHsType. This function is not exported, but you can look around at other functions in that module to see if there's an exported one that serves your needs. You may need to convert the HsType to a Type (Type is the same as TcType, roughly) and then call typeKind.

I hope this helps!
Richard

On Jul 20, 2014, at 8:45 AM, Alejandro Serrano Mena <trupill <at> gmail.com> wrote:

Dear Haskell-café,
I'm trying to get some information of the kinds of types in a program. In particular, I want to obtain the kinds of arguments to type family instances, that is, given:

type family F a b :: Nat
type instance F (List k) b = b

I would like to obtain the kinds of "k" and "b" in the left-hand side of the type instance.

In particular, I'm obtaining type family instance information via LTyFamInstEqn [http://www.haskell.org/ghc/docs/latest/html/libraries/ghc/HsDecls.html#t:LTyFamInstEqn]. Inside, I get a list of binders of type HsWithBndrs [LHsType name]. I'm assuming each of the LHsTypes inside is a pattern in the type family instance. Thus, I'm looking at those elements and try to find their kind there.

Thus, the specific question is: given a HsType, can I obtain its kind somehow?

Thanks in advance
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe



_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Gmane