<div dir="ltr">There is always the possibility of using GHC.Ptr as a home for it instead of Foreign.Ptr. The main reason I would want this in base rather than just some library is that, as a library author, I would never pick up an extra dependency for something that trivial.<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Aug 17, 2020 at 10:52 AM David Feuer <<a href="mailto:david.feuer@gmail.com">david.feuer@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">In the context of GHC Haskell, that's definitely the Right Thing. I think what might concern some people is that pattern synonyms as we know them are a very GHC thing, while the Ptr business is pretty much Report Haskell. </div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Aug 17, 2020, 10:44 AM Andrew Martin <<a href="mailto:andrew.thaddeus@gmail.com" target="_blank">andrew.thaddeus@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Foreign.Ptr provides nullPtr. It would make some of my code more terse if this was additionally provided as a pattern synonym. The pattern synonym can be defined as:</div><div><br></div><div> {-# language ViewPatterns #-}<br> {-# language PatternSynonyms #-}<br> module NullPointerPattern<br> ( pattern Null<br> ) where<br> import Foreign.Ptr (Ptr,nullPtr)<br> pattern Null :: Ptr a<br> pattern Null <- ((\x -> x == nullPtr) -> True)<br> where Null = nullPtr</div><div><br></div><div>Any here is example of code that becomes more terse once this is available:</div><div><br></div><div> foo :: IO (Either Error (Ptr Foo))</div><div> foo = do</div><div> p <- initialize mySettings</div><div> if p == nullPtr</div><div> then pure (Left InitializeFailure)<br></div><div> else pure (Right p)</div><div><br></div><div>With the pattern synonym, we are able to take advantage of LambdaCase:</div><div><br></div><div><div> foo :: IO (Either Error (Ptr Foo))</div><div> foo = initialize mySettings >>= \case</div><div> Null -> pure (Left InitializeFailure)<br></div><div> p -> pure (Right p)</div></div><div><div><br></div><div>I'm curious what others think.<br></div><div><br>-- <br><div dir="ltr">-Andrew Thaddeus Martin</div></div></div></div>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" rel="noreferrer" target="_blank">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature">-Andrew Thaddeus Martin</div>