Changes between Initial Version and Version 2 of Ticket #13307


Ignore:
Timestamp:
Feb 20, 2017 2:53:57 PM (3 years ago)
Author:
simonpj
Comment:

Yes, with plain old newtype T you could say

module A( T(..) ) where 

newtype T = MkT { x :: Impl }

to export both MkT and x along with T.

But in the example ocharles wants to bundle the pattern synonym data constructor MkT2 in with the type constructor T. Maybe you would like to say

module A( T( MkT, MkT2(..) ) where ...

to mean the same as T( MkT, MkT2, x ). But we don't currently support that (nested dot-dot notation).

I suppose you could alternatively say that the notation T( MkT, MkT2, .. ) means "T together with data constructor/pattern synonyms MkT and MkT2, plus their field names". But that would be a (modest) design change.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #13307 – Description

    initial v2  
    33{{{#!hs
    44{-# LANGUAGE PatternSynonyms #-}
    5 module A
    6   ( T(T)
    7   ) where
     5module A( T( MkT2 ) ) where
    86
    97data Impl = Impl Int
     
    119newtype T = MkT Impl
    1210
    13 pattern T {x} = MkT (Impl x)
     11pattern MkT2 {x} = MkT (Impl x)
    1412
    1513{-# LANGUAGE RecordWildCards #-}
     
    1917
    2018foo :: T -> Int
    21 foo T{x} = x
     19foo MkT2{x} = x
    2220}}}
    2321
    24 As far as GHC can see, in module `B`, `T` does not have a field `x`. The fix is to manually export `x` from `A`:
     22As far as GHC can see, in module `B`, `MkT2` does not have a field `x`. The fix is to manually export `x` from `A`:
    2523
    2624{{{#!hs
    27 module A (T(T, x)) where
     25module A (T(MkT2, x)) where
    2826}}}
    2927