<div><div dir="auto">That’s a really nice idea !</div></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Aug 18, 2020 at 2:54 AM Henning Thielemann <<a href="mailto:lemming@henning-thielemann.de">lemming@henning-thielemann.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)"><br><br>On Mon, 17 Aug 2020, Carter Schonwald wrote:<br><br><br><br>> There’s an interesting idea or two in here.  Like, should we support <br><br>> having non-nullable pointers?<br><br><br><br>That was my first idea, too.<br><br><br><br>newtype NonNullPtr a = NonNullPtr (Ptr a)<br><br><br><br>maybeNonNull :: Ptr a -> Maybe (NonNullPtr a)<br><br><br><br>Using NonNullPtr in FFI declarations would make the interfaces safer.<br><br><br><br>E.g.<br><br>    dst <- mallocArray n<br><br>    for (maybeNonNull dst) $ \dstNonNull -><br><br>       copyArray dstNonNull srcNonNull n<br><br><br><br>That seems better than testing for nullPtr and then forgeting this <br><br>information in the type, again.</blockquote></div></div>