fpco / inline-c

284 stars 50 forks source link

Sundials Types Part I #71

Open idontgetoutmuch opened 6 years ago

idontgetoutmuch commented 6 years ago

I am trying to use sundials via inline-c. I am starting to define the types some of which are quite complex :( Even the simplest seems to throw up problems. For example what should I do here?

#if defined(SUNDIALS_INT64_T)

#if __STDC_VERSION__ >= 199901L
typedef int64_t sunindextype;
#else
typedef long int sunindextype;
#endif

#elif defined(SUNDIALS_INT32_T)

#if __STDC_VERSION__ >= 199901L
typedef int32_t sunindextype;
#else
typedef int sunindextype;
#endif

#endif

At the moment I have this

-- This is a lie!!!
type SunIndexType = CLong

sunTypesTable :: Map.Map CT.TypeSpecifier TH.TypeQ
sunTypesTable = Map.fromList
  [
    (CT.TypeName "sunindextype", [t| SunIndexType |] )
  ]

sunctx = mempty {ctxTypesTable = sunTypesTable}
idontgetoutmuch commented 6 years ago

Ah but maybe I don't need to do this anyway.

stites commented 5 years ago

@idontgetoutmuch how did you resolve this?

idontgetoutmuch commented 5 years ago

I don't think I did resolve that particular issue but it's all working - see here: https://github.com/haskell-numerics/hmatrix-sundials/blob/master/src/Numeric/Sundials/Arkode.hsc

ekmett commented 5 years ago

My best work around for this sort of issue is to use hsc2hs and inline-c in the same Haskell module.

With hsc2hs you can use

type SunIndexType = #type sunindextype

and then the rest of your code is correct.

idontgetoutmuch commented 5 years ago

👍