#5529: Newtypes with hidden constructors cannot be passed as FFI arguments
-----------------------------------+----------------------------------------
    Reporter:  mikhail.vorozhtsov  |        Owner:              
        Type:  bug                 |       Status:  new         
    Priority:  normal              |    Milestone:              
   Component:  Compiler            |      Version:  7.3         
    Keywords:                      |     Testcase:              
   Blockedby:                      |   Difficulty:              
          Os:  Unknown/Multiple    |     Blocking:              
Architecture:  Unknown/Multiple    |      Failure:  None/Unknown
-----------------------------------+----------------------------------------

Comment(by mikhail.vorozhtsov):

 > This goes way beyond the original ticket, and I must admit I'm having
 trouble following your arguments.
 My point is that, given the current level of integration between GHC and C
 compilers, exporting constructors does not make programmers more confident
 in their FFI imports signatures.

 > > My other (original) concern is that exporting a constructor does not
 only reveal the representation of the type, but also, obviously, gives
 third party non-FFI code a way to construct instances of the type. For
 CTime it may be ok, but think about flag types, which are allowed to have
 only limited number of bits set (or, even worse, only limited number of
 combinations of set bits).
 >
 > But you want to give clients the ability to call arbitrary foreign
 functions that return the type!  Allowing them to construct instances in
 Haskell is no worse than that.
 I disagree. It's like saying that, since we provide a way to construct
 instances via unsafeCoerce, we should just export everything. To me FFI is
 like unsafeCoerce, you can break things with it, but it requires a certain
 amount of ''conscious'' effort to do so. Then the programmer sees
 unsafeCoerce or "foreign import", he naturally checks things twice. On the
 other hand, constructing "incoherent" instance using the newtype
 constructor is just way too easy.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5529#comment:13>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to