How to export type constructors when using the DataKinds extension?

Playback using advanced type. I want to name the name and several type constructors that produce types of this kind:

{-# LANGUAGE DataKinds #-}

data Subject = New | Existing

Here, as I understand it, we called kind Subjectand type constructors Newand Existing, which :: Subject. These type constructors do not accept arguments (I plan to use them as phantom types), this should be roughly equivalent:

{-# LANGUAGE EmptyDataDecls #-}

data New
data Existing

With the difference that now I can write:

{-# LANGUAGE DataKinds      #-}
{-# LANGUAGE GADTs          #-}
{-# LANGUAGE KindSignatures #-}

-- …

data MyConfig :: Subject -> * -> * where
  MyConfig
    { mcOneThing :: Path t File
    } :: MyConfig k t

. , , , -, Subject, Subject (?). , ( New Existing ; , New Existing Subject). " , , , ".

, New Existing - , . , :

foo :: MyConfig New Dir -> …

foo :: MyConfig Int Dir -> …

.

:

module MyModule
  ( New
  , Existing
  -- …
  )
where

:

"

<

GHC 7.9.3 , " " ', :

module MyModule
  ( 'New
  , 'Existing
  -- …
  )
where

... .


New Existing, , - ?

+4
1

:

module MyModule (Subject(..)) where

data Subject = New | Existing

, , , .

, DataKinds MyModule, , .

+4

Source: https://habr.com/ru/post/1622884/


All Articles