<div dir="ltr">The concept you are looking for is "phantom type": a type that is used solely as a "tag" of sorts, with no associated data. The Ptr type constructor uses a phantom type so you can differentiate between machine addresses pointing at different kinds of data and gain some small measure of safety.</div><br><div class="gmail_quote"><div dir="ltr">On Wed, Nov 7, 2018 at 8:20 AM Guru Devanla <<a href="mailto:gurudev.devanla@gmail.com">gurudev.devanla@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr">Thank you all for the responses, After reading through the responses, it became clear that this is a commonly pattern used in Haskell FFI programming. <br></div><div dir="ltr"><br></div><div dir="ltr"> I went back and reviewed the chapter in RWH. There is a discussion on this pattern, under 'Typed Pointers'.  <br></div><div dir="ltr"><a href="http://book.realworldhaskell.org/read/interfacing-with-c-the-ffi.html" target="_blank">http://book.realworldhaskell.org/read/interfacing-with-c-the-ffi.html</a></div><div dir="ltr"><br></div><div>Which means similar to the type listed in the chapter<pre id="m_-7313302863422328447gmail-PCRE-recursive.hs:nullary" class="m_-7313302863422328447gmail-programlisting"><span style="font-family:arial,helvetica,sans-serif">newtype PCRE = PCRE (Ptr PCRE)</span></pre></div><div dir="ltr"><div><pre id="m_-7313302863422328447gmail-PCRE-recursive.hs:nullary" class="m_-7313302863422328447gmail-programlisting"><span style="font-family:arial,helvetica,sans-serif"><span class="m_-7313302863422328447gmail-m_-8878328436277233588gmail-keyword">The example I provided reduces to:<br>newtype</span> <a id="m_-7313302863422328447gmail-m_-8878328436277233588gmail-t:XEvent" class="m_-7313302863422328447gmail-m_-8878328436277233588gmail-def">XEvent = XEvent (Ptr XEvent). --  a recursive newtype that cannot be dereferenced<br></a><a id="m_-7313302863422328447gmail-m_-8878328436277233588gmail-t:XEvent" class="m_-7313302863422328447gmail-m_-8878328436277233588gmail-def"><br>In summary:<br></a></span></pre><pre id="m_-7313302863422328447gmail-PCRE-recursive.hs:nullary" class="m_-7313302863422328447gmail-programlisting"><span style="font-family:arial,helvetica,sans-serif">1. This pattern can be use to specify the types just for type-checking within Haskell. They do not contain any data. Therefore, not data can be cerated for XEvent.<br>2.  Data can be created for type `Ptr XEvent` using the `alloca` interface, and only way to de-reference these values would be through `peek`. But, while derefencing the resulting values will have other types.<br><br>Next, I plan to spend some time working on these examples to get a better sense.<br></span></pre><pre id="m_-7313302863422328447gmail-PCRE-recursive.hs:nullary" class="m_-7313302863422328447gmail-programlisting"><span style="font-family:arial,helvetica,sans-serif">Thank you all!</span><span style="font-family:monospace,monospace"><br></span></pre><pre id="m_-7313302863422328447gmail-PCRE-recursive.hs:nullary" class="m_-7313302863422328447gmail-programlisting"><span style="font-family:monospace,monospace"><br><br> <br><br></span></pre><pre id="m_-7313302863422328447gmail-PCRE-recursive.hs:nullary" class="m_-7313302863422328447gmail-programlisting"><span style="font-family:monospace,monospace"><a id="m_-7313302863422328447gmail-m_-8878328436277233588gmail-t:XEvent" class="m_-7313302863422328447gmail-m_-8878328436277233588gmail-def"><br><br></a></span></pre></div></div><div dir="ltr"><br></div><div dir="ltr"><br></div><div dir="ltr"><br></div><div dir="ltr"><br></div><div dir="ltr"><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Nov 7, 2018 at 2:29 AM Theodore Lief Gannon <<a href="mailto:tanuki@gmail.com" target="_blank">tanuki@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>The meaning of XEvent is different on the left and right sides of the newtype declaration. On the left, it's a type; on the right, it's a data constructor. The constructor wraps a value which refers to the type, but not recursively back to the constructor itself.</div><div dir="auto"><br><div class="gmail_quote" dir="auto"><div dir="ltr">On Tue, Nov 6, 2018, 8:36 AM Guru Devanla <<a href="mailto:gurudev.devanla@gmail.com" target="_blank">gurudev.devanla@gmail.com</a> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div>Hello Haskell-Cafe,</div><div><br></div><div>I have been recently studying the XMonad code and some related types available in the X11 bindings library.</div><div><br></div><div>I came across this type: <br></div><span class="m_-7313302863422328447m_2710547797220449863m_6650469407821808840gmail-keyword"><br></span></div><div dir="ltr"><span class="m_-7313302863422328447m_2710547797220449863m_6650469407821808840gmail-keyword">newtype</span> <a id="m_-7313302863422328447m_2710547797220449863m_6650469407821808840gmail-t:XEvent" class="m_-7313302863422328447m_2710547797220449863m_6650469407821808840gmail-def" rel="noreferrer">XEvent = XEvent XEventPtr</a><div><a id="m_-7313302863422328447m_2710547797220449863m_6650469407821808840gmail-t:XEvent" class="m_-7313302863422328447m_2710547797220449863m_6650469407821808840gmail-def" rel="noreferrer"><br></a></div><div><font size="2"><span class="m_-7313302863422328447m_2710547797220449863m_6650469407821808840gmail-keyword">type</span> <a id="m_-7313302863422328447m_2710547797220449863m_6650469407821808840gmail-t:XEventPtr" class="m_-7313302863422328447m_2710547797220449863m_6650469407821808840gmail-def" rel="noreferrer">XEventPtr</a> = <a href="http://hackage.haskell.org/package/base-4.10.1.0/docs/Foreign-Ptr.html#t:Ptr" rel="noreferrer" target="_blank">Ptr</a> <a href="http://hackage.haskell.org/package/X11-1.9/docs/Graphics-X11-Xlib-Event.html#t:XEvent" rel="noreferrer" target="_blank">XEvent</a></font></div><div><font size="2"><br></font></div><div><font size="2">Available here:  </font><br></div><div><a href="http://hackage.haskell.org/package/X11-1.9/docs/Graphics-X11-Xlib-Event.html#t:XEvent" rel="noreferrer" target="_blank">http://hackage.haskell.org/package/X11-1.9/docs/Graphics-X11-Xlib-Event.html#t:XEvent</a></div><div><font size="2"><br></font></div><div><font size="2">It seems that this type is circular here. how does one use this type? Is it possible to create a value out of this type? What is the use of this type?<br></font></div><div><font size="2"><br></font></div><div><font size="2">Please could someone help me wrap my head around this?<br></font></div><div><font size="2"><br></font></div><div><font size="2">Thanks</font></div><div><font size="2"><br></font></div><div><font size="2"><br></font></div><div><font size="2"><br></font></div><div><br></div><div><br></div><div><br></div></div></div>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div></div></div>
</blockquote></div>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>brandon s allbery kf8nh</div><div><a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a></div></div></div></div></div>