an unsafe API for adding functions to the grammar. breaks referential transparency

This commit is contained in:
krangelov
2021-09-04 07:10:04 +02:00
parent 55d30d70f5
commit 9a2d2b345d
4 changed files with 44 additions and 0 deletions

View File

@@ -40,6 +40,8 @@ module PGF2 (-- * PGF
mkType, unType,
mkHypo, mkDepHypo, mkImplHypo,
createFunction,
-- * Concrete syntax
ConcName,
@@ -315,3 +317,10 @@ readType str =
freeStablePtr c_ty
return (Just ty)
createFunction :: PGF -> Fun -> Type -> Float -> IO ()
createFunction p name ty prob =
withForeignPtr (a_pgf p) $ \p_pgf ->
withText name $ \c_name ->
bracket (newStablePtr ty) freeStablePtr $ \c_ty ->
withForeignPtr marshaller $ \m -> do
pgf_create_function p_pgf c_name c_ty prob m