That’s a really nice idea !

On Tue, Aug 18, 2020 at 2:54 AM Henning Thielemann <lemming@henning-thielemann.de> wrote:


On Mon, 17 Aug 2020, Carter Schonwald wrote:



> There’s an interesting idea or two in here.  Like, should we support

> having non-nullable pointers?



That was my first idea, too.



newtype NonNullPtr a = NonNullPtr (Ptr a)



maybeNonNull :: Ptr a -> Maybe (NonNullPtr a)



Using NonNullPtr in FFI declarations would make the interfaces safer.



E.g.

    dst <- mallocArray n

    for (maybeNonNull dst) $ \dstNonNull ->

       copyArray dstNonNull srcNonNull n



That seems better than testing for nullPtr and then forgeting this

information in the type, again.