Defining a wired-in type of a different kind

Hi, when trying to get familiar with the GHC code base for my Bachelor's thesis. I followed the GHC Wiki, especially the case study about the bool type. Now I wanted to add a new kind and a new type inhabiting this kind (without having to expose a data constructor, so without datatype promotion). So in TysWiredIn.hs I added the new TyCons and added them to the list of wired-in types: -- data Row a b rowKindCon :: TyCon rowKindCon = pcTyCon rowKindConName Nothing [alphaTyVar, betaTyVar] [] rowKind :: Kind rowKind = mkTyConTy rowKindCon -- data RNil :: Row a b rnilTyCon :: TyCon rnilTyCon = mkAlgTyCon rnilTyConName [] rowKind [] Nothing [] (mkDataTyConRhs []) (VanillaAlgTyCon (mkPrelTyConRepName rnilTyConName)) False rnilTy :: Type rnilTy = mkTyConTy rnilTyCon I also added two new empty data decls to ghc-prim, but if I inspect the kind of RNil it is not Row, but Type. So I think I am either understanding res_kind wrong or I have to do something completely different. I am also not sure how to verify that the code in TysWiredIn.hs is working at all, from all what I can tell it could just be the declarations in ghc-prim that result in what I see in ghci. Thank you and sorry for my beginner question Jan

On April 3, 2019 7:06:11 AM EDT, "Jan van Brügge"
Hi,
when trying to get familiar with the GHC code base for my Bachelor's thesis. I followed the GHC Wiki, especially the case study about the bool type. Now I wanted to add a new kind and a new type inhabiting this kind (without having to expose a data constructor, so without datatype promotion).
So in TysWiredIn.hs I added the new TyCons and added them to the list of wired-in types:
-- data Row a b rowKindCon :: TyCon rowKindCon = pcTyCon rowKindConName Nothing [alphaTyVar, betaTyVar] []
rowKind :: Kind rowKind = mkTyConTy rowKindCon
-- data RNil :: Row a b rnilTyCon :: TyCon rnilTyCon = mkAlgTyCon rnilTyConName [] rowKind [] Nothing [] (mkDataTyConRhs []) (VanillaAlgTyCon (mkPrelTyConRepName rnilTyConName)) False
rnilTy :: Type rnilTy = mkTyConTy rnilTyCon
I also added two new empty data decls to ghc-prim, but if I inspect the kind of RNil it is not Row, but Type. So I think I am either understanding res_kind wrong or I have to do something completely different. I am also not sure how to verify that the code in TysWiredIn.hs is working at all, from all what I can tell it could just be the declarations in ghc-prim that result in what I see in ghci.
Thank you and sorry for my beginner question Jan
Can you post a full branch? Nothing in particular looks wrong with what you posted here but the PrelNames code is also relevant. Cheers, - Ben

Yeah, sorry, it is here: https://gitlab.haskell.org/jvanbruegge/ghc/commit/73b383275f3d497338ca50a3a7... Am 03.04.19 um 13:11 schrieb Ben Gamari:
On April 3, 2019 7:06:11 AM EDT, "Jan van Brügge"
wrote: Hi,
when trying to get familiar with the GHC code base for my Bachelor's thesis. I followed the GHC Wiki, especially the case study about the bool type. Now I wanted to add a new kind and a new type inhabiting this kind (without having to expose a data constructor, so without datatype promotion).
So in TysWiredIn.hs I added the new TyCons and added them to the list of wired-in types:
-- data Row a b rowKindCon :: TyCon rowKindCon = pcTyCon rowKindConName Nothing [alphaTyVar, betaTyVar] []
rowKind :: Kind rowKind = mkTyConTy rowKindCon
-- data RNil :: Row a b rnilTyCon :: TyCon rnilTyCon = mkAlgTyCon rnilTyConName [] rowKind [] Nothing [] (mkDataTyConRhs []) (VanillaAlgTyCon (mkPrelTyConRepName rnilTyConName)) False
rnilTy :: Type rnilTy = mkTyConTy rnilTyCon
I also added two new empty data decls to ghc-prim, but if I inspect the kind of RNil it is not Row, but Type. So I think I am either understanding res_kind wrong or I have to do something completely different. I am also not sure how to verify that the code in TysWiredIn.hs is working at all, from all what I can tell it could just be the declarations in ghc-prim that result in what I see in ghci.
Thank you and sorry for my beginner question Jan Can you post a full branch? Nothing in particular looks wrong with what you posted here but the PrelNames code is also relevant.
Cheers,
- Ben

Make sure you add the new wired in this to `TysWiredIn.wiredInTyCons`
From: ghc-devs

I did, see here: https://gitlab.haskell.org/jvanbruegge/ghc/blob/73b383275f3d497338ca50a3a793... Am 03.04.19 um 16:28 schrieb Simon Peyton Jones:
Make sure you add the new wired in this to `TysWiredIn.wiredInTyCons`
*From:*ghc-devs
*On Behalf Of *Jan van Brügge *Sent:* 03 April 2019 12:06 *To:* ghc-devs@haskell.org *Subject:* Defining a wired-in type of a different kind
Hi, when trying to get familiar with the GHC code base for my Bachelor's thesis. I followed the GHC Wiki, especially the case study about the bool type. Now I wanted to add a new kind and a new type inhabiting this kind (without having to expose a data constructor, so without datatype promotion). So in TysWiredIn.hs I added the new TyCons and added them to the list of wired-in types: -- data Row a b rowKindCon :: TyCon rowKindCon = pcTyCon rowKindConName Nothing [alphaTyVar, betaTyVar] [] rowKind :: Kind rowKind = mkTyConTy rowKindCon -- data RNil :: Row a b rnilTyCon :: TyCon rnilTyCon = mkAlgTyCon rnilTyConName [] rowKind [] Nothing [] (mkDataTyConRhs []) (VanillaAlgTyCon (mkPrelTyConRepName rnilTyConName)) False rnilTy :: Type rnilTy = mkTyConTy rnilTyCon I also added two new empty data decls to ghc-prim, but if I inspect the kind of RNil it is not Row, but Type. So I think I am either understanding res_kind wrong or I have to do something completely different. I am also not sure how to verify that the code in TysWiredIn.hs is working at all, from all what I can tell it could just be the declarations in ghc-prim that result in what I see in ghci. Thank you and sorry for my beginner question Jan

I would suggest that it's easier to define a normal type constructor
and data cons and then promote them.
This is how the runtime rep polymorphism stuff works for instance so
you can look there for inspiration (it's where I look to work out how
to implement multiplicity polymorphism).
Matt
On Wed, Apr 3, 2019 at 12:06 PM Jan van Brügge
Hi,
when trying to get familiar with the GHC code base for my Bachelor's thesis. I followed the GHC Wiki, especially the case study about the bool type. Now I wanted to add a new kind and a new type inhabiting this kind (without having to expose a data constructor, so without datatype promotion).
So in TysWiredIn.hs I added the new TyCons and added them to the list of wired-in types:
-- data Row a b rowKindCon :: TyCon rowKindCon = pcTyCon rowKindConName Nothing [alphaTyVar, betaTyVar] []
rowKind :: Kind rowKind = mkTyConTy rowKindCon
-- data RNil :: Row a b rnilTyCon :: TyCon rnilTyCon = mkAlgTyCon rnilTyConName [] rowKind [] Nothing [] (mkDataTyConRhs []) (VanillaAlgTyCon (mkPrelTyConRepName rnilTyConName)) False
rnilTy :: Type rnilTy = mkTyConTy rnilTyCon
I also added two new empty data decls to ghc-prim, but if I inspect the kind of RNil it is not Row, but Type. So I think I am either understanding res_kind wrong or I have to do something completely different. I am also not sure how to verify that the code in TysWiredIn.hs is working at all, from all what I can tell it could just be the declarations in ghc-prim that result in what I see in ghci.
Thank you and sorry for my beginner question Jan
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

Hi Jan, mkAlgTyCon is good for making an algebraic datatype -- like Maybe or Bool or Either. It's not what you want for RNil, which is really a data constructor. Instead, rowKindCon should be the algebraic datatype, and RNil should be one of its constructors. Then you get the RNil TyCon via promotion, as Matt suggested. I hope this helps! Richard
On Apr 3, 2019, at 7:06 AM, Jan van Brügge
wrote: Hi,
when trying to get familiar with the GHC code base for my Bachelor's thesis. I followed the GHC Wiki, especially the case study about the bool type. Now I wanted to add a new kind and a new type inhabiting this kind (without having to expose a data constructor, so without datatype promotion).
So in TysWiredIn.hs I added the new TyCons and added them to the list of wired-in types:
-- data Row a b rowKindCon :: TyCon rowKindCon = pcTyCon rowKindConName Nothing [alphaTyVar, betaTyVar] []
rowKind :: Kind rowKind = mkTyConTy rowKindCon
-- data RNil :: Row a b rnilTyCon :: TyCon rnilTyCon = mkAlgTyCon rnilTyConName [] rowKind [] Nothing [] (mkDataTyConRhs []) (VanillaAlgTyCon (mkPrelTyConRepName rnilTyConName)) False
rnilTy :: Type rnilTy = mkTyConTy rnilTyCon
I also added two new empty data decls to ghc-prim, but if I inspect the kind of RNil it is not Row, but Type. So I think I am either understanding res_kind wrong or I have to do something completely different. I am also not sure how to verify that the code in TysWiredIn.hs is working at all, from all what I can tell it could just be the declarations in ghc-prim that result in what I see in ghci.
Thank you and sorry for my beginner question Jan
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
participants (5)
-
Ben Gamari
-
Jan van Brügge
-
Matthew Pickering
-
Richard Eisenberg
-
Simon Peyton Jones