On Fri, Dec 04, 2026 at 11:54:48PM +0100, Henning Thielemann wrote:
However, that crazy idea stops working when I actually try to construct a Value:
int64Value :: forall ctx. Int64 -> IO (Value ctx Int64) int64Value @context n = withForeignPtr context $ \ctx -> withCString (show n) $ \cstr -> do typ <- FFI.intTypeInContext ctx 64 fmap Value $ FFI.constIntOfString typ cstr 10
GHC-10.0 rejects with:
• Illegal term-level use of the type variable ‘context’
Is it expected that this would work with further extensions from the Dependent Haskell roadmap? With what extensions? Or is it already possible with todays extensions?
In principle it works with the singletons library: int64Value :: forall ctx. SingKind (ForeignPtr FFIContext) => SingI cxt => Int64 -> IO (Value ctx Int64) int64Value @context n = withForeignPtr (demote context) $ \ctx -> withCString (show n) $ \cstr -> do typ <- FFI.intTypeInContext ctx 64 fmap Value $ FFI.constIntOfString typ cstr 10 However, in practice you'd have to work out a way of writing SingI instance for types of kind `ForeignPtr t`. I suppose it's possible that you could do what `KnownNat` does (`KnownNat` is basically `SingI Nat`) and define newtype SForeignPtr a (p :: ForeignPtr a) = UnsafeForeignPtr_ (ForeignPtr a) Maybe that gives you somewhere to start looking? Tom