[Haskell-cafe] Help understanding this type

Guru Devanla gurudev.devanla at gmail.com
Wed Nov 7 13:20:16 UTC 2018

Thank you all for the responses, After reading through the responses, it
became clear that this is a commonly pattern used in Haskell FFI

I went back and reviewed the chapter in RWH. There is a discussion on this
pattern, under 'Typed Pointers'.

Which means similar to the type listed in the chapter

newtype PCRE = PCRE (Ptr PCRE)

The example I provided reduces to:
newtype XEvent = XEvent (Ptr XEvent). --  a recursive newtype that
cannot be dereferenced

In summary:

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.
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

Next, I plan to spend some time working on these examples to get a better sense.

Thank you all!

On Wed, Nov 7, 2018 at 2:29 AM Theodore Lief Gannon <tanuki at gmail.com>

> 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.
> On Tue, Nov 6, 2018, 8:36 AM Guru Devanla <gurudev.devanla at gmail.com
> wrote:
>> Hello Haskell-Cafe,
>> I have been recently studying the XMonad code and some related types
>> available in the X11 bindings library.
>> I came across this type:
>> newtype XEvent = XEvent XEventPtr
>> type XEventPtr = Ptr
>> <http://hackage.haskell.org/package/base->
>> XEvent
>> <http://hackage.haskell.org/package/X11-1.9/docs/Graphics-X11-Xlib-Event.html#t:XEvent>
>> Available here:
>> http://hackage.haskell.org/package/X11-1.9/docs/Graphics-X11-Xlib-Event.html#t:XEvent
>> 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?
>> Please could someone help me wrap my head around this?
>> Thanks
>> _______________________________________________
>> Haskell-Cafe mailing list
>> To (un)subscribe, modify options or view archives go to:
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20181107/7135ec1d/attachment.html>

More information about the Haskell-Cafe mailing list