title: inline-c : "`Type` cannot be marshalled in a foreign call"
body: <h3>Setting</h3>
  
  <p>A C enum type rendered into Haskell by c2hs, complete with <code>Storable</code> instance which compiles correctly (<code>TypesC2Hs.chs</code>). I import this unqualified into the module I have assigned for the <code>inline-c</code> context (<code>Internal.hs</code>). Both the <code>.hs</code> module generated by c2hs and <code>Internal.hs</code> are imported by <code>InlineC.hs</code>, the other <code>inline-c</code> module that holds the quasiquotes wrapping the C calls. </p>
  
  <pre><code>TypesC2Hs.hs ------------- 
      |                    |
      V                    V
  Internal.hs -------&gt; InlineC.hs
  </code></pre>
  
  <h3>Question</h3>
  
  <p><code>InlineC.hs</code> complains that this type cannot be marshalled: "Unacceptable argument type in foreign declaration: ‘DMBoundaryType’ cannot be marshalled in a foreign call When checking declaration:"</p>
  
  <p>What is going on? This is the first time <code>inline-c</code> gives me type of this error. </p>
  
  <p>I should note that other types that do not need to be dereferenced directly, e.g. <code>newtype DM = DM (Ptr DM) deriving Storable</code>, work fine with the above approach. </p>
  
  <p>Thanks in advance</p>
  
  <hr>
  
  <p>TypesC2Hs.chs</p>
  
  <pre><code>{# enum DMBoundaryType as DMBoundaryType {underscoreToCase} deriving (Eq, Show) #}
  
  instance Storable DMBoundaryType where
    sizeOf _ = {# sizeof DMBoundaryType #}
    alignment _ = {# alignof DMBoundaryType #}
    peek = peek
    poke = poke
  </code></pre>
  
  <p>Internal.hs</p>
  
  <pre><code>{-# LANGUAGE QuasiQuotes, TemplateHaskell ,GeneralizedNewtypeDeriving, StandaloneDeriving ,DeriveDataTypeable, DataKinds, OverloadedStrings #-}
  
  module Internal where
  
  import TypesC2Hs
  
  import qualified Language.C.Inline         as C
  import qualified Language.C.Types          as CT
  import           Language.C.Inline.Context
  
  import qualified Language.Haskell.TH       as TH
  
  import           Data.Monoid               ((&lt;&gt;), mempty)
  import qualified Data.Map                  as Map
  
  
  ctx :: Context
  ctx = baseCtx &lt;&gt; funCtx &lt;&gt; vecCtx &lt;&gt; bsCtx &lt;&gt; pctx where
    pctx = mempty {ctxTypesTable = typesTable}
  
  
  typesTable :: Map.Map CT.TypeSpecifier TH.TypeQ  
  typesTable = Map.fromList
                [ (CT.TypeName "DMBoundaryType", [t| DMBoundaryType |])  ]
  </code></pre>
  
  <p>InlineC.hs</p>
  
  <pre><code>dmdaCreate1d0' cc bx m dof s =
     withPtr ( \ dm -&gt; [C.exp|int{DMDACreate1d($(int c),
                                                $(DMBoundaryType bx),
                                                $(PetscInt m),
                                                $(PetscInt dof),
                                                $(PetscInt s),
                                                NULL,
                                                $(DM* dm))}|]  )
    where c = unComm cc
  </code></pre>